fmsystem-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Fmsystem-commits] [12787] property: integrate with controller


From: Sigurd Nes
Subject: [Fmsystem-commits] [12787] property: integrate with controller
Date: Tue, 24 Feb 2015 11:52:42 +0000

Revision: 12787
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=12787
Author:   sigurdne
Date:     2015-02-24 11:52:41 +0000 (Tue, 24 Feb 2015)
Log Message:
-----------
property: integrate with controller

Modified Paths:
--------------
    trunk/property/inc/class.boentity.inc.php
    trunk/property/inc/class.uientity.inc.php
    trunk/property/templates/base/entity.xsl

Modified: trunk/property/inc/class.boentity.inc.php
===================================================================
--- trunk/property/inc/class.boentity.inc.php   2015-02-24 11:51:13 UTC (rev 
12786)
+++ trunk/property/inc/class.boentity.inc.php   2015-02-24 11:52:41 UTC (rev 
12787)
@@ -60,7 +60,8 @@
                                'read_single'   => true,
                                'save'                  => true,
                                'delete'                => true,
-                               'check_perms'   => true
+                               'check_perms'   => true,
+                               'add_control'   => true
                        );
 
                var $type_app = array();
@@ -900,4 +901,123 @@
                        return $this->so->edit_inventory($values);
                }
 
+               public function add_control()
+               {
+                       $entity_id                              = 
phpgw::get_var('entity_id', 'int');
+                       $cat_id                                 = 
phpgw::get_var('cat_id', 'int');
+                       $id                                             = 
phpgw::get_var('id', 'int');
+                       $type                                   = 
phpgw::get_var('type', 'string', 'REQUEST', 'entity');
+                       $control_id                             = 
phpgw::get_var('control_id', 'int');
+                       $assigned_to                    = 
phpgw::get_var('control_responsible', 'int');
+                       $start_date                             = 
phpgw::get_var('control_start_date', 'string');
+
+                       $component_arr = 
$this->so->read_single(array('entity_id' => $entity_id, 'cat_id'=> $cat_id, 
'id' => $id));
+
+                       $location_code = $component_arr['location_code'];
+
+                       if($start_date)
+                       {
+                               phpgw::import_class('phpgwapi.datetime');
+                               $start_date = 
phpgwapi_datetime::date_to_timestamp($start_date);
+                       }
+
+                       $result =  array
+                       (
+                               'status_kode'=> 'error',
+                               'status'        => lang('error'),
+                               'msg'           => lang('Missing input')
+                       );
+
+                       if($control_id && $assigned_to && $id)
+                       {
+                               if(!$GLOBALS['phpgw']->acl->check('.admin', 
PHPGW_ACL_EDIT, 'property'))
+                               {
+                                       $receipt['error'][]=true;
+                                       $result =  array
+                                       (
+                                               'status_kode'=> 'error',
+                                               'status'        => 
lang('error'),
+                                               'msg'           => lang('you 
are not approved for this task')
+                                       );
+
+                               }
+                               if(!$receipt['error'])
+                               {
+                                       $location_id = 
$GLOBALS['phpgw']->locations->get_id( $this->type_app[$type], 
".{$type}.{$entity_id}.{$cat_id}");
+
+                                       $so_control     = 
CreateObject('controller.socontrol');
+                                       $values = array
+                                       (
+                                               'register_component'    => 
array("{$control_id}_{$location_id}_{$id}"),
+                                               'assigned_to'                   
=> $assigned_to,
+                                               'start_date'                    
=> $start_date
+                                       );
+
+                                       
if($so_control->register_control_to_component($values))
+                                       {
+                                               
$this->add_check_list(array('location_id'=>$location_id, 'component_id' => $id, 
'control_id' => $control_id, 'assigned_to' => $assigned_to, 'start_date' => 
$start_date, 'location_code' => $location_code));
+                                               $result =  array
+                                               (
+                                                       'status_kode'=> 'ok',
+                                                       'status'        => 'Ok',
+                                                       'msg'           => 
lang('updated')
+
+                                               );
+                                       }
+                                       else
+                                       {
+                                               $result =  array
+                                               (
+                                                       'status_kode'=> 'error',
+                                                       'status'        => 
lang('error'),
+                                                       'msg'           => 'Noe 
gikk galt'
+                                               );
+                                       }
+                               }
+                       }
+                       return $result;
+               }
+
+               function add_check_list($data = array())
+               {
+                       phpgw::import_class('controller.socheck_list');
+                       include_class('controller', 'check_list', 'inc/model/');
+
+                       $control_id = $data['control_id'];
+                       $type = 'component';
+                       $comment = '';
+                       $assigned_to = $data['assigned_to'];
+                       $billable_hours = phpgw::get_var('billable_hours', 
'float');
+
+                       $deadline_date_ts = $data['start_date'];
+                       $planned_date_ts        = $deadline_date_ts;
+                       $completed_date_ts      = 0;
+
+                       $check_list = new controller_check_list();
+                       $check_list->set_control_id($control_id);
+                       $check_list->set_location_code($data['location_code']);
+                       $check_list->set_location_id($data['location_id']);
+                       $check_list->set_component_id($data['component_id']);
+
+                       $status = controller_check_list::STATUS_NOT_DONE;
+                       $check_list->set_status($status);
+                       $check_list->set_comment($comment);
+                       $check_list->set_deadline($deadline_date_ts);
+                       $check_list->set_planned_date($planned_date_ts);
+                       $check_list->set_completed_date($completed_date_ts);
+                       $check_list->set_assigned_to($assigned_to);
+                       $check_list->set_billable_hours($billable_hours);
+
+                       $socheck_list = CreateObject('controller.socheck_list');
+
+                       if($check_list->validate() && $check_list_id = 
$socheck_list->store($check_list))
+                       {
+                               return $check_list_id ;
+                       }
+                       else
+                       {
+                               return false;
+                       }
+               }
+
        }

Modified: trunk/property/inc/class.uientity.inc.php
===================================================================
--- trunk/property/inc/class.uientity.inc.php   2015-02-24 11:51:13 UTC (rev 
12786)
+++ trunk/property/inc/class.uientity.inc.php   2015-02-24 11:52:41 UTC (rev 
12787)
@@ -69,7 +69,8 @@
                                'get_inventory'         => true,
                                'add_inventory'         => true,
                                'edit_inventory'        => true,
-                               'inventory_calendar'=> true
+                               'inventory_calendar'=> true,
+                       'get_controls_at_component'=>true
                        );
 
                function property_uientity()
@@ -1955,6 +1956,13 @@
                                        $active_tab = $active_tab ? $active_tab 
: 'location';
                                }
 
+                               if(true)
+                               {
+                                       $tabs['controller']     = array('label' 
=> lang('controller'), 'link' => '#controller', 'function' => 
"set_tab('controller')");
+                                       $active_tab = $active_tab ? $active_tab 
: 'location';
+                                       
$GLOBALS['phpgw']->jqcal->add_listener('control_start_date');
+                               }
+
                                $location = 
".{$this->type}.{$this->entity_id}.{$this->cat_id}";
                                $attributes_groups = 
$this->bo->get_attribute_groups($location, $values['attributes']);
 
@@ -2384,7 +2392,7 @@
                                );
 
 
-                               if($category['enable_bulk'])
+//                             if($category['enable_bulk'])
                                {
                                        $tabs['inventory']      = array('label' 
=> lang('inventory'), 'link' => '#inventory', 'function' => 
"set_tab('inventory')");
 
@@ -2424,7 +2432,38 @@
                                }
 
                        }
+                                       $_controls = 
$this->get_controls_at_component($location_id, $id);
 
+                                       $datavalues[4] = array
+                                       (
+                                               'name'                          
        => "4",
+                                               'values'                        
        => json_encode($_controls),
+                                               'total_records'                 
=> count($_controls),
+                                               'edit_action'                   
=> "''",
+                                               'is_paginator'                  
=> 0,
+                                               'footer'                        
        => 1
+                                       );
+
+                                       $myColumnDefs[4] = array
+                                       (
+                                               'name'          => "4",
+                                               'values'        =>      
json_encode(array(
+                                                               array('key' => 
'control_id','label'=>lang('id'),'sortable'=>false,'resizeable'=>true),
+                                                               array('key' => 
'title','label'=>lang('title'),'sortable'=>false,'resizeable'=>true),
+                                                               array('key' => 
'assigned_to_name','label'=>lang('user'),'sortable'=>false,'resizeable'=>true),
+                                                               array('key' => 
'start_date','label'=>lang('start date'),'sortable'=>false,'resizeable'=>true),
+                                                               array('key' => 
'repeat_type','label'=>lang('repeat 
type'),'sortable'=>false,'resizeable'=>true),
+                                                               array('key' => 
'repeat_interval','label'=>lang('repeat 
interval'),'sortable'=>false,'resizeable'=>true),
+               //                                              array('key' => 
'enabled','label'=>lang('enabled'),'sortable'=>false,'resizeable'=>true),
+                                                               array('key' => 
'location_id','hidden'=>true),
+                                                               array('key' => 
'component_id','hidden'=>true),
+                                                               array('key' => 
'id','hidden'=>true),
+                                                               array('key' => 
'assigned_to','hidden'=>true),
+                                                       )
+                                               )
+                                       );
+                               
+
                        $property_js = "/property/js/yahoo/property2.js";
 
                        if 
(!isset($GLOBALS['phpgw_info']['server']['no_jscombine']) || 
!$GLOBALS['phpgw_info']['server']['no_jscombine'])
@@ -2452,6 +2491,7 @@
 
                        $data = array
                        (
+                                       'controller'                            
        => true,
                                        'property_js'                           
        => json_encode($GLOBALS['phpgw_info']['server']['webserver_url'] . 
$property_js),
                                        'datatable'                             
                => $datavalues,
                                        'myColumnDefs'                          
        => $myColumnDefs,       
@@ -3434,4 +3474,67 @@
                        echo "Planlagt: Visning av kalenderoppføringer for 
ressursen";
                        $GLOBALS['phpgw']->common->phpgw_exit();
                }
+
+               public function get_controls_at_component( $location_id = 0, 
$id = 0 )
+               {
+                       if(!$location_id)
+                       {
+                               $entity_id                              = 
phpgw::get_var('entity_id', 'int');
+                               $cat_id                                 = 
phpgw::get_var('cat_id', 'int');
+                               $type                                   = 
phpgw::get_var('type', 'string', 'REQUEST', 'entity');
+
+                               $location_id = 
$GLOBALS['phpgw']->locations->get_id( $this->type_app[$type], 
".{$type}.{$entity_id}.{$cat_id}");
+                       }
+
+                       $id                             = $id ? $id : 
phpgw::get_var('id', 'int');
+
+                       if(!$this->acl_read)
+                       {
+                               echo lang('No Access');
+                               $GLOBALS['phpgw']->common->phpgw_exit();
+                       }
+
+                       $repeat_type_array = array
+                               (
+                                       "0"=> lang('day'),
+                                       "1"=> lang('week'),
+                                       "2"=> lang('month'),
+                                       "3"=> lang('year')
+                               );
+
+                       $control_link_data = array
+                               (
+                                       'menuaction'    => 
'controller.uicalendar.view_calendar_year_for_locations',
+                                       'control_id'    => $entry['control_id'],
+                                       'location_id'   => $location_id,
+                                       'component_id'  => $id,
+                               );
+
+                       $controls = 
execMethod('controller.socontrol.get_controls_at_component', 
array('location_id' => $location_id, 'component_id' => $id));
+                       foreach($controls as &$entry)
+                       {
+                               $menuaction     = 
'controller.uicalendar.view_calendar_year_for_locations';
+                               if($entry['repeat_type'] < 2)
+                               {
+                                       $menuaction     = 
'controller.uicalendar.view_calendar_month_for_locations';
+                               }
+
+                               $control_link_data = array
+                               (
+                                       'menuaction'    => $menuaction,
+                                       'control_id'    => $entry['control_id'],
+                                       'location_id'   => $location_id,
+                                       'component_id'  => $id,
+                               );
+                               $entry['title'] = '<a 
href="'.$GLOBALS['phpgw']->link('/index.php',$control_link_data).'" 
target="_blank">'.$entry['title'].'</a>';
+
+                               $entry['start_date'] =  
$GLOBALS['phpgw']->common->show_date($entry['start_date'],$GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']);
+                               $entry['repeat_type'] = 
$repeat_type_array[$entry['repeat_type']];
+                       }
+                       if( phpgw::get_var('phpgw_return_as') == 'json' )
+                       {
+                                       return json_encode($controls);
+                       }
+                       return $controls;
+               }
        }

Modified: trunk/property/templates/base/entity.xsl
===================================================================
--- trunk/property/templates/base/entity.xsl    2015-02-24 11:51:13 UTC (rev 
12786)
+++ trunk/property/templates/base/entity.xsl    2015-02-24 11:52:41 UTC (rev 
12787)
@@ -527,7 +527,7 @@
                                                                </td>
                                                                <td>
                                                                        
<xsl:value-of select="value_num"/>
-                                                                       <input 
type="hidden" name="location_code" value="{location_code}"/>
+                                                                       <input 
type="hidden" id="location_code" name="location_code" value="{location_code}"/>
                                                                        <input 
type="hidden" name="lookup_tenant" value="{lookup_tenant}"/>
                                                                        <input 
type="hidden" name="values[id]" value="{value_id}"/>
                                                                        <input 
type="hidden" name="values[num]" value="{value_num}"/>
@@ -624,6 +624,139 @@
                                                        </div>
                                                </xsl:when>
                                        </xsl:choose>
+                                       <xsl:if test="controller!=''">
+                                               <div id="controller">
+                                                       <script 
type="text/javascript">
+                                                       
lookup_control_responsible = function()
+                                                       {
+                                                               var oArgs = 
{menuaction:'property.uilookup.phpgw_user', column:'control_responsible'};
+                                                               var requestUrl 
= phpGWLink('index.php', oArgs);
+                                                               var 
Window1=window.open(requestUrl,"Search","left=50,top=100,width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");
+                                                       }
+
+                                                       lookup_control = 
function()
+                                                       {
+                                                               var oArgs = 
{menuaction:'controller.uilookup.control'};
+                                                               var requestUrl 
= phpGWLink('index.php', oArgs);
+                                                               var 
Window1=window.open(requestUrl,"Search","left=50,top=100,width=800,height=700,toolbar=no,scrollbars=yes,resizable=yes");
+                                                       }
+<![CDATA[
+                                                       function parseURL(url)
+                                                       {
+                                                               var parser = 
document.createElement('a'),
+                                                                       
searchObject = {},
+                                                                       
queries, split, i;
+                                                               // Let the 
browser do the work
+                                                               parser.href = 
url;
+                                                               // Convert 
query string to object
+                                                               queries = 
parser.search.replace(/^\?/, '').split('&');
+                                                               for( i = 0; i < 
queries.length; i++ ) {
+                                                                       split = 
queries[i].split('=');
+                                                                       
searchObject[split[0]] = split[1];
+                                                               }
+                                                               return {
+                                                                       
protocol: parser.protocol,
+                                                                       host: 
parser.host,
+                                                                       
hostname: parser.hostname,
+                                                                       port: 
parser.port,
+                                                                       
pathname: parser.pathname,
+                                                                       search: 
parser.search,
+                                                                       
searchObject: searchObject,
+                                                                       hash: 
parser.hash
+                                                               };
+                                                       }
+]]>
+                                                       add_control = function()
+                                                       {
+                                                               var formUrl = 
$("#form").attr("action");
+                                                               var Url = 
parseURL(formUrl);
+                                                               oArgs  = 
Url.searchObject;
+                                                               delete 
oArgs.click_history;
+                                                               
oArgs.menuaction = 'property.boentity.add_control';
+                                                               
oArgs.control_id = $("#control_id").val();
+                                                               
oArgs.control_responsible = $("#control_responsible").val();
+                                                               
oArgs.control_start_date = $("#control_start_date").val();
+
+                                                               var requestUrl 
= phpGWLink('index.php', oArgs, true);
+//                                                             
alert(requestUrl);
+
+                                                               
$("#controller_receipt").html("");
+
+                                                               $.ajax({
+                                                                       type: 
'POST',
+                                                                       
dataType: 'json',
+                                                                       url: 
requestUrl,
+                                                                       
success: function(data) {
+                                                                               
if( data != null)
+                                                                               
{
+                                                                               
        $("#controller_receipt").html(data.status + '::' + data.msg);
+                                                                               
        if(data.status_kode == 'ok')
+                                                                               
        {
+                                                                               
                $("#control_id").val('');
+                                                                               
                $("#control_name").val('');
+                                                                               
                $("#control_responsible").val('');
+                                                                               
                $("#control_responsible_user_name").val('');
+                                                                               
                $("#control_start_date").val('');
+                                                                               
        }
+                                                                               
}
+                                                                       }
+                                                               });
+
+                                                               var oArgs2 = 
{menuaction:'property.uientity.get_controls_at_component', type:oArgs.type, 
entity_id:oArgs.entity_id, cat_id:oArgs.cat_id, id: oArgs.id};
+                                                               var requestUrl2 
= phpGWLink('index.php', oArgs2, true);
+                                                               
execute_async(myDataTable_4, oArgs2);
+                                                       };
+
+                                                       </script>
+                                                       <div 
id="controller_receipt"></div>
+                                                       <fieldset>
+                                                               <legend>
+                                                                       
<xsl:value-of select="php:function('lang', 'new')" />
+                                                               </legend>
+                                                               <label>
+                                                                       
<xsl:value-of select="php:function('lang', 'user')" />
+                                                               </label>
+                                                               <input 
type="text" name="control_responsible" id="control_responsible" value="" 
onClick="lookup_control_responsible();" readonly="readonly" size="6">
+                                                               </input>
+                                                               <input 
size="30" type="text" name="control_responsible_user_name" 
id="control_responsible_user_name" value="" 
onClick="lookup_control_responsible();" readonly="readonly">
+                                                               </input>
+                                                               <br/>
+                                                               <label>
+                                                                       
<xsl:value-of select="php:function('lang', 'controller')" />
+                                                               </label>
+                                                               <input 
type="text" name="control_id" id="control_id" value="" 
onClick="lookup_control();" readonly="readonly" size="6">
+                                                               </input>
+                                                               <input 
type="text" name="control_name" id="control_name" value="" 
onClick="lookup_control();" readonly="readonly" size="30">
+                                                               </input>
+                                                               <xsl:variable 
name="lang_add">
+                                                                       
<xsl:value-of select="php:function('lang', 'add')"/>
+                                                               </xsl:variable>
+                                                               <br/>
+
+                                                               <label>
+                                                                       
<xsl:value-of select="php:function('lang', 'start date')" />
+                                                               </label>
+                                                               <input 
type="text" name="control_start_date" id="control_start_date" value=""  
readonly="readonly" size="10">
+                                                               </input>
+                                                               <br/>
+
+                                                               <input 
type="button" name="" value="{$lang_add}" title="{$lang_add}" 
onClick="add_control();">
+                                                               </input>
+
+                                                       </fieldset>
+                                                               <table 
cellpadding="2" cellspacing="2" width="80%" align="center">
+                                                                       <tr>
+                                                                               
<td>
+                                                                               
        <div id="datatable-container_4"/>
+                                                                               
</td>
+                                                                       </tr>
+                                                               </table>
+
+                                                       <xsl:call-template 
name="controller_integration">
+                                                               <xsl:with-param 
name="controller" select ='controller'/>
+                                                       </xsl:call-template>
+                                               </div>
+                                       </xsl:if>
                                        <xsl:call-template 
name="attributes_values"/>
                                        <xsl:choose>
                                                <xsl:when test="files!='' or 
fileupload = 1">
@@ -946,3 +1079,8 @@
                        </xsl:when>
                </xsl:choose>
        </xsl:template>
+
+       <xsl:template name="controller_integration">
+               <xsl:param name="controller" />
+               
+       </xsl:template>
\ No newline at end of file




reply via email to

[Prev in Thread] Current Thread [Next in Thread]