fmsystem-commits
[Top][All Lists]
Advanced

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

[Fmsystem-commits] [10433]


From: Torstein
Subject: [Fmsystem-commits] [10433]
Date: Fri, 02 Nov 2012 12:54:04 +0000

Revision: 10433
          http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=10433
Author:   vator
Date:     2012-11-02 12:54:04 +0000 (Fri, 02 Nov 2012)
Log Message:
-----------


Modified Paths:
--------------
    trunk/logistic/inc/class.sorequirement_resource_allocation.inc.php
    trunk/logistic/inc/class.uirequirement_resource_allocation.inc.php
    trunk/logistic/js/logistic/resource_allocation.js

Removed Paths:
-------------
    trunk/logistic/inc/class.uiallocation.inc.php

Modified: trunk/logistic/inc/class.sorequirement_resource_allocation.inc.php
===================================================================
--- trunk/logistic/inc/class.sorequirement_resource_allocation.inc.php  
2012-11-02 11:43:04 UTC (rev 10432)
+++ trunk/logistic/inc/class.sorequirement_resource_allocation.inc.php  
2012-11-02 12:54:04 UTC (rev 10433)
@@ -179,6 +179,21 @@
 
                        return $allocation;
                }
+               
+               function delete($resource_allocation_id)
+               {
+                       $resource_allocation_id = (int) $resource_allocation_id;
+                       $status = $this->db->query("DELETE FROM 
lg_requirement_resource_allocation WHERE id = $resource_allocation_id");
+                                       
+                       if( $status )
+                       {
+                               return true;
+                       }
+                       else
+                       {
+                               return false;
+                       }
+               }
 
                public static function get_instance()
                {

Deleted: trunk/logistic/inc/class.uiallocation.inc.php
===================================================================
--- trunk/logistic/inc/class.uiallocation.inc.php       2012-11-02 11:43:04 UTC 
(rev 10432)
+++ trunk/logistic/inc/class.uiallocation.inc.php       2012-11-02 12:54:04 UTC 
(rev 10433)
@@ -1,308 +0,0 @@
-<?php
-
-       /**
-        * phpGroupWare - logistic: a part of a Facilities Management System.
-        *
-        * @author Erik Holm-Larsen <address@hidden>
-        * @copyright Copyright (C) 2011,2012 Free Software Foundation, Inc. 
http://www.fsf.org/
-        * This file is part of phpGroupWare.
-        *
-        * phpGroupWare is free software; you can redistribute it and/or modify
-        * it under the terms of the GNU General Public License as published by
-        * the Free Software Foundation; either version 2 of the License, or
-        * (at your option) any later version.
-        *
-        * phpGroupWare is distributed in the hope that it will be useful,
-        * but WITHOUT ANY WARRANTY; without even the implied warranty of
-        * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-        * GNU General Public License for more details.
-        *
-        * You should have received a copy of the GNU General Public License
-        * along with phpGroupWare; if not, write to the Free Software
-        * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  
02110-1301  USA
-        *
-        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
-        * @internal Development of this application was funded by 
http://www.bergen.kommune.no/
-        * @package property
-        * @subpackage logistic
-        * @version $Id: class.uiactivity.inc.php 10101 2012-10-03 09:46:51Z 
vator $
-        */
-       phpgw::import_class('phpgwapi.uicommon');
-       phpgw::import_class('logistic.soactivity');
-       include_class('logistic', 'activity');
-       
-       /*
-       class logistic_uiallocation extends phpgwapi_uicommon
-       {
-               
-               var $cat_id;
-               var $start;
-               var $query;
-               var $sort;
-               var $order;
-               var $filter;
-               var $type_id;
-               var $location_code;
-               
-               private $bo;
-               private $bocommon;
-               private $so_activity;
-               
-               public $public_functions = array(
-                       'query' => true,
-                       'add'   => true,
-                       'edit' => true,
-                       'view' => true,
-                       'index' => true
-               );
-
-               public function __construct()
-               {
-                       parent::__construct();
-                       
-                 $this->bo                                     = 
CreateObject('property.bolocation',true);
-                       $this->bocommon                         = & 
$this->bo->bocommon;
-                       
-                       $this->so_activity = 
createObject('logistic.soactivity');
-                       
-                       $this->type_id                          = 
$this->bo->type_id;
-                       
-                       $this->start                            = 
$this->bo->start;
-                       $this->query                            = 
$this->bo->query;
-                       $this->sort                                     = 
$this->bo->sort;
-                       $this->order                            = 
$this->bo->order;
-                       $this->filter                           = 
$this->bo->filter;
-                       $this->cat_id                           = 
$this->bo->cat_id;
-                       $this->part_of_town_id          = 
$this->bo->part_of_town_id;
-                       $this->district_id                      = 
$this->bo->district_id;
-                       $this->status                           = 
$this->bo->status;
-                       $this->allrows                          = 
$this->bo->allrows;
-                       $this->lookup                           = 
$this->bo->lookup;
-                       $this->location_code            = 
$this->bo->location_code;
-
-                       $GLOBALS['phpgw_info']['flags']['menu_selection'] = 
"logistic::project::allocation";
-               }
-               
-               public function index()
-               {
-                       if (phpgw::get_var('phpgw_return_as') == 'json')
-                       {
-                               return $this->query();
-                       }
-                       self::add_javascript('phpgwapi', 'yahoo', 
'datatable.js');
-                       phpgwapi_yui::load_widget('datatable');
-                       phpgwapi_yui::load_widget('paginator');
-
-                       $user_array = $this->get_user_array();
-
-                       $data = array(
-                               'datatable_name'        => lang('allocation'),
-                               'form' => array(
-                                       'toolbar' => array(
-                                               'item' => array(
-                                                       array('type' => 
'filter',
-                                                               'name' => 
'project',
-                                                               'text' => 
lang('Project') . ':',
-                                                               'list' => 
$project_array,
-                                                       ),
-                                                       array('type' => 
'filter',
-                                                               'name' => 
'user',
-                                                               'text' => 
lang('Responsible user') . ':',
-                                                               'list' => 
$user_array,
-                                                       ),
-                                                       array('type' => 'text',
-                                                               'text' => 
lang('search'),
-                                                               'name' => 
'query'
-                                                       ),
-                                                       array(
-                                                               'type' => 
'submit',
-                                                               'name' => 
'search',
-                                                               'value' => 
lang('Search')
-                                                       ),
-                                               ),
-                                       ),
-                               ),
-                               'datatable' => array(
-                                       'source' => 
self::link(array('menuaction' => 'logistic.uiallocation.index', 
'phpgw_return_as' => 'json')),
-                                       'field' => array(
-                                       array(
-                                                       'key' => 'id',
-                                                       'label' => lang('ID'),
-                                                       'sortable' => true,
-                                               ),              
-                                               array(
-                                                       'key' => 
'location_code',
-                                                       'label' => 
lang('Location code'),
-                                                       'sortable' => true
-                                               ),
-                                               array(
-                                                       'key' => 'address',
-                                                       'label' => 
lang('Address'),
-                                                       'sortable' => false
-                                               )
-                                       )
-                               ),
-                       );
-
-                       self::render_template_xsl(array('datatable_common'), 
$data);
-               }
-
-               public function query()
-               {
-                       $params = array(
-                               'start' => phpgw::get_var('startIndex', 'int', 
'REQUEST', 0),
-                               'query' => phpgw::get_var('query'),
-                               'sort' => phpgw::get_var('sort'),
-                               'dir' => phpgw::get_var('dir'),
-                               'filters' => $filters
-                       );
-                       
-                 $entity_id                    = phpgw::get_var('entity_id', 
'int');
-                       $cat_id                         = 
phpgw::get_var('cat_id', 'int');
-                       $district_id            = phpgw::get_var('district_id', 
'int');
-                       $part_of_town_id        = 
phpgw::get_var('part_of_town_id', 'int');
-                       $control_id                     = 
phpgw::get_var('control_id', 'int');
-                       $results                        = 
phpgw::get_var('results', 'int');
-                       
-
-                       $entity_id = 3;
-                       $cat_id = 1;
-                               $location_id = 
2295;//$GLOBALS['phpgw']->locations->get_id('property', 
".entity.{$entity_id}.{$cat_id}");
-                               //$boentity     = 
CreateObject('property.boentity',false, 'entity');
-                               $boentity       = 
CreateObject('property.boentity',false, 'entity', $entity_id, $cat_id);
-                               $boentity->results = $results;
-                               //$values = 
$boentity->read(array('control_registered' => $control_registered, 'control_id' 
=> $control_id));
-                               $values = $boentity->read();
-                       //}     
-
-                       $results = $results ? $results : 
$GLOBALS['phpgw_info']['user']['preferences']['common']['maxmatchs'];
-
-                       $result_data = array('results' => $values);
-
-                       $result_data['total_records'] = 
$boentity->total_records;
-                       $result_data['start'] = $params['start'];
-                       $result_data['sort'] = $params['sort'];
-                       $result_data['dir'] = $params['dir'];
-                       
-                       return $this->yui_results($result_data);
-               }
-
-               public function add()
-               {
-                       $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'logistic.uiallocation.edit'));
-               }
-
-               public function edit()
-               {
-                       $activity_id = phpgw::get_var('activity_id');
-                       $allocation_id = phpgw::get_var('id');
-                       
-                       if ($activity_id && is_numeric($activity_id))
-                       {
-                               $activity = 
$this->so_activity->get_single($activity_id);
-                       }
-                       
-                       if (isset($_POST['save_allocation']))
-                       {
-                               $allocation = new 
logistic_requirement_resource_allocation();
-                               $allocation->set_id(phpgw::get_var('id'));
-                               
$allocation->set_requirement_id(phpgw::get_var('requirement_id'));
-                               
$allocation->set_article_id(phpgw::get_var('article_id'));
-                               $allocation->set_type(phpgw::get_var('type'));
-                               
-       //                      $allocation_id = $this->so->store($allocation);
-
-                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'logistic.uiallocation.view', 'id' => $allocation_id));
-                       }
-                       else if (isset($_POST['cancel_allocation']))
-                       {
-                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'logistic.uiallocation.view', 'id' => $allocation_id));
-                       }
-                       else
-                       {
-                               $accounts = 
$GLOBALS['phpgw']->acl->get_user_list_right(PHPGW_ACL_READ, 'run', 'logistic');
-
-               
-                               $data = array
-                               (
-                                       'editable' => true,
-                               );
-                               
-                               if($activity_id > 0)
-                               {
-                                       $data['activity'] = $activity;
-                               }
-                               
-                               
self::render_template_xsl(array('allocation/allocation_item'), $data);
-                       }
-               }
-               
-               function convert_to_array($object_list)
-               {
-                       $converted_array = array();
-                       
-                       foreach($object_list as $object)
-                       {
-                               $converted_array[] = $object->toArray();
-                       }
-                       
-                       return $converted_array; 
-               }
-
-               public function view()
-               {
-                       $activity_id = phpgw::get_var('id');
-                       $project_id = phpgw::get_var('project_id');
-                       if (isset($_POST['edit_activity']))
-                       {
-                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'logistic.uiactivity.edit', 'id' => $activity_id, 
'project_id' => $project_id));
-                       }
-                       else if (isset($_POST['new_activity']))
-                       {
-                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'logistic.uiactivity.edit', 'project_id' => $project_id));
-                       }
-                       else
-                       {
-                               if ($activity_id && is_numeric($activity_id))
-                               {
-                                       $activity = 
$this->so->get_single($activity_id);
-                               }
-
-                               $activity_array = $activity->toArray();
-
-                               if ($this->flash_msgs)
-                               {
-                                       $msgbox_data = 
$GLOBALS['phpgw']->common->msgbox_data($this->flash_msgs);
-                                       $msgbox_data = 
$GLOBALS['phpgw']->common->msgbox($msgbox_data);
-                               }
-
-                               $activity->set_project_id($project_id);
-
-                               $data = array
-                                       (
-                                               'activity' => 
$activity->toArray(),
-                                               'dateformat'                    
        => $GLOBALS['phpgw_info']['user']['preferences']['common']['dateformat']
-                               );
-
-                               $GLOBALS['phpgw_info']['flags']['app_header'] = 
lang('logistic') . '::' . lang('Project');
-                               
self::render_template_xsl(array('activity_item'), $data);
-                       }
-               }
-
-               private function get_user_array()
-               {
-                       $user_array = array();
-                       $user_array[] = array(
-                               'id' => '',
-                               'name' => lang('all_types')
-                       );
-                       $user_array[] = array(
-                               'id' => 
$GLOBALS['phpgw_info']['user']['account_id'],
-                               'name' => lang('my_activities'),
-                               'selected' => 1
-                       );
-
-                       return $user_array;
-               }
-       }
-*/
\ No newline at end of file

Modified: trunk/logistic/inc/class.uirequirement_resource_allocation.inc.php
===================================================================
--- trunk/logistic/inc/class.uirequirement_resource_allocation.inc.php  
2012-11-02 11:43:04 UTC (rev 10432)
+++ trunk/logistic/inc/class.uirequirement_resource_allocation.inc.php  
2012-11-02 12:54:04 UTC (rev 10433)
@@ -60,7 +60,8 @@
                        'edit' => true,
                        'view' => true,
                        'index' => true,
-                       'save' => true
+                       'save' => true,
+                       'delete' => true
                );
 
                public function __construct()
@@ -229,9 +230,13 @@
                        {
                                if (isset($result))
                                {
-                                       $requirement = $result->serialize();
+                                       $requirement = $result->serialize();    
                
                                        
-                                       $delete_href = 
self::link(array('menuaction' => 
'logistic.uirequirementresource_allocation.delete', 'id' => 
$requirement['id']));
+                                       $delete_href = self::link(
+                                                                               
                                                array('menuaction' => 
'logistic.uirequirement_resource_allocation.delete', 
+                                                                               
                                                                        'id' => 
$requirement['id'], 
+                                                                               
                                                                        
'phpgw_return_as' => 'json')
+                                                                               
                                                );
                                        $requirement['delete_link'] = "<a 
class=\"btn-sm delete\" href=\"{$delete_href}\">Slett</a>";
                                        $rows[] = $requirement;
                                }
@@ -374,26 +379,54 @@
                                $requirement = 
$this->so_requirement->get_single($requirement_id);
                        }
                        
+                       $user_id = $GLOBALS['phpgw_info']['user']['id'];
                        $chosen_resources = phpgw::get_var('chosen_resources');
                        
-                       $user_id = $GLOBALS['phpgw_info']['user']['id'];
+                       $filters = array('requirement_id' => 
$requirement->get_id());
+                       $num_allocated = 
$this->so_resource_allocation->get_count($search_for, $search_type, $filters); 
+                                                        
+                       $num_required = $requirement->get_no_of_items();
+                                                       
+                       $num_allowed_bookings = $num_required - $num_required;
                        
-                       foreach($chosen_resources as $resource_id)
+                       
+                       if( count($chosen_resources) <=  $num_allowed_bookings)
                        {
-                               $resource_alloc = new 
logistic_requirement_resource_allocation();
-                               $resource_alloc->set_requirement_id( 
$requirement->get_id() );
-                               $resource_alloc->set_resource_id( $resource_id 
);
-                               $resource_alloc->set_location_id( 
$requirement->get_location_id() );
-                               $resource_alloc->set_create_user( $user_id );
+                               foreach($chosen_resources as $resource_id)
+                               {
+                                       $resource_alloc = new 
logistic_requirement_resource_allocation();
+                                       $resource_alloc->set_requirement_id( 
$requirement->get_id() );
+                                       $resource_alloc->set_resource_id( 
$resource_id );
+                                       $resource_alloc->set_location_id( 
$requirement->get_location_id() );
+                                       $resource_alloc->set_create_user( 
$user_id );
+                                       
+                                       $resource_alloc_id = $this->so->store( 
$resource_alloc );
+                               }
                                
-                               $resource_alloc_id = $this->so->store( 
$resource_alloc );
+                               $activity_id = 
$this->so_activity->get_single($requirement->get_activity_id()); 
+       
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'logistic.uiactivity.view_resource_allocation', 
'activity_id' => $activity_id));
                        }
-                       
-                       $activity_id = 
$this->so_activity->get_single($requirement->get_activity_id()); 
-
-                       $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 'logistic.uiactivity.view_resource_allocation', 
'activity_id' => $activity_id));
+                       else
+                       {
+                               $GLOBALS['phpgw']->redirect_link('/index.php', 
array('menuaction' => 
'logistic.uirequirement_resource_allocation.view_resource_allocation', 
'requirement_id' => $requirement_id));
+                       }
                }
                
+               public function delete()
+               {
+                       $resource_allocation_id = phpgw::get_var('id');
+                               
+                       $status = $this->so->delete($resource_allocation_id);
+               
+                       if($status){
+                               return json_encode( array( "status" => 
"deleted" ) );
+                       }
+                       else{
+                               return json_encode( array( "status" => 
"not_deleted" ) );
+                       }
+               } 
+               
                function convert_to_array($object_list)
                {
                        $converted_array = array();

Modified: trunk/logistic/js/logistic/resource_allocation.js
===================================================================
--- trunk/logistic/js/logistic/resource_allocation.js   2012-11-02 11:43:04 UTC 
(rev 10432)
+++ trunk/logistic/js/logistic/resource_allocation.js   2012-11-02 12:54:04 UTC 
(rev 10433)
@@ -7,6 +7,31 @@
                
                updateAllocationTable( requirement_id );
     });
+       
+       $("#allocation-container table .btn-sm.delete").live("click", 
function(e){
+               var thisRow = $(this).parents("tr");
+               
+               var requestUrl = $(this).attr("href");
+               
+               $.ajax({
+                         type: 'POST',
+                         url: requestUrl,
+                         success: function(data) {
+                                 var obj = jQuery.parseJSON(data);
+                         
+                         if(obj.status == "deleted"){
+                                 $(thisRow).remove();
+                                 }
+                         },
+                         error: function(XMLHttpRequest, textStatus, 
errorThrown) {
+                   if (XMLHttpRequest.status === 401) {
+                     location.href = '/';
+                   }
+                         }
+               });
+               
+               return false;
+    });
 });
 
 




reply via email to

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