[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Fmsystem-commits] [7664] controller: separate example-code
From: |
Sigurd Nes |
Subject: |
[Fmsystem-commits] [7664] controller: separate example-code |
Date: |
Tue, 20 Sep 2011 07:41:13 +0000 |
Revision: 7664
http://svn.sv.gnu.org/viewvc/?view=rev&root=fmsystem&revision=7664
Author: sigurdne
Date: 2011-09-20 07:41:12 +0000 (Tue, 20 Sep 2011)
Log Message:
-----------
controller: separate example-code
Modified Paths:
--------------
trunk/controller/inc/class.menu.inc.php
Added Paths:
-----------
trunk/controller/inc/class.uiexample.inc.php
trunk/controller/js/yahoo/example_edit.js
trunk/controller/templates/base/example_edit.xsl
Modified: trunk/controller/inc/class.menu.inc.php
===================================================================
--- trunk/controller/inc/class.menu.inc.php 2011-09-20 07:17:36 UTC (rev
7663)
+++ trunk/controller/inc/class.menu.inc.php 2011-09-20 07:41:12 UTC (rev
7664)
@@ -50,6 +50,29 @@
)
),
+ 'example' => array
+ (
+ 'text' => 'example',
+ 'url' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uiexample.index') ),
+ 'image' => array('property', 'location_1'),
+ 'children' => array(
+ 'edit' => array
+
+ (
+ 'text'
=> 'example::edit',
+ 'url'
=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'controller.uiexample.edit') ),
+ 'image'
=> array('rental', 'x-office-spreadsheet')
+ ),
+ 'separate_tabs'
=> array
+
+ (
+ 'text'
=> 'example::separate_tabs',
+ 'url'
=> $GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'controller.uiexample.separate_tabs') ),
+ 'image'
=> array('rental', 'x-office-spreadsheet')
+ ),
+
+ )
+ ),
'procedure' => array
(
'text' => lang('Procedure'),
Added: trunk/controller/inc/class.uiexample.inc.php
===================================================================
--- trunk/controller/inc/class.uiexample.inc.php
(rev 0)
+++ trunk/controller/inc/class.uiexample.inc.php 2011-09-20 07:41:12 UTC
(rev 7664)
@@ -0,0 +1,482 @@
+<?php
+ phpgw::import_class('controller.uicommon');
+ phpgw::import_class('property.boevent');
+ phpgw::import_class('controller.socontrol');
+ phpgw::import_class('controller.socontrol_item');
+ phpgw::import_class('controller.socontrol_group');
+
+ include_class('controller', 'control', 'inc/model/');
+
+ class controller_uiexample extends controller_uicommon
+ {
+ private $bo;
+ private $so;
+ private $so_proc;
+
+ public $public_functions = array
+ (
+ 'index' => true,
+ 'edit' => true,
+ 'separate_tabs' => true,
+ 'delete' => true,
+ 'js_poll' => true
+ );
+
+ public function __construct()
+ {
+ parent::__construct();
+ $this->so = CreateObject('controller.socontrol');
+ $this->so_control_item =
CreateObject('controller.socontrol_item');
+ $this->so_control_group =
CreateObject('controller.socontrol_group');
+ $this->bo = CreateObject('property.boevent',true);
+ }
+
+ public function index()
+ {
+ self::set_active_menu('controller::example');
+ if(phpgw::get_var('phpgw_return_as') == 'json') {
+ return $this->index_json();
+ }
+ $this->bo = CreateObject('booking.boapplication');
+ $GLOBALS['phpgw_info']['apps']['manual']['section'] =
'booking_manual';
+ self::add_javascript('controller', 'yahoo',
'datatable.js');
+ phpgwapi_yui::load_widget('datatable');
+ phpgwapi_yui::load_widget('paginator');
+
+ $data = array(
+ 'form' => array(
+ 'toolbar' => array(
+ 'item' => array(
+ array(
+ 'type' =>
'link',
+ 'value' =>
lang('New application'),
+ 'href' =>
self::link(array('menuaction' => 'controller.uiexample.index'))
+ ),
+ array('type' =>
'filter',
+ 'name' =>
'status',
+ 'text' => lang('Status').':',
+ 'list' => array(
+ array(
+ 'id' => 'none',
+ 'name' => lang('Not selected')
+ ),
+ array(
+ 'id' => 'NEW',
+ 'name' => lang('NEW')
+ ),
+ array(
+ 'id' => 'PENDING',
+ 'name' => lang('PENDING')
+ ),
+ array(
+ 'id' => 'REJECTED',
+ 'name' => lang('REJECTED')
+ ),
+ array(
+ 'id' => 'ACCEPTED',
+ 'name' => lang('ACCEPTED')
+ )
+ )
+ ),
+ array('type' =>
'filter',
+ 'name' =>
'buildings',
+ 'text' => lang('Building').':',
+ 'list' => $this->bo->so->get_buildings(),
+ ),
+ array('type' =>
'filter',
+ 'name' =>
'activities',
+ 'text' => lang('Activity').':',
+ 'list' =>
$this->bo->so->get_activities_main_level(),
+ ),
+ array('type' => 'text',
+ 'text' => lang('searchfield'),
+ 'name' =>
'query'
+ ),
+ array(
+ 'type' =>
'submit',
+ 'name' =>
'search',
+ 'value' =>
lang('Search')
+ ),
+ array(
+ 'type' =>
'link',
+ 'value' =>
$_SESSION['showall'] ? lang('Show only active') : lang('Show all'),
+ 'href' =>
self::link(array('menuaction' => $this->url_prefix.'.toggle_show_inactive'))
+ ),
+ ),
+ ),
+ ),
+ 'datatable' => array
+ (
+ 'source' =>
self::link(array('menuaction' => 'controller.uiexample.index',
'phpgw_return_as' => 'json')),
+ 'field' => array(
+ array(
+ 'key' => 'id',
+ 'label' => lang('ID'),
+ 'sortable' => true,
+ 'formatter' =>
'YAHOO.portico.formatLink'
+ ),
+ array(
+ 'key' => 'status',
+ 'label' =>
lang('Status'),
+ 'sortable' => false
+ ),
+ array(
+ 'key' =>
'building_name',
+ 'label' =>
lang('Building'),
+ 'sortable' => true
+ ),
+ array(
+ 'key' => 'what',
+ 'label' => lang('What'),
+ 'sortable' => false
+ ),
+ array(
+ 'key' => 'created',
+ 'label' =>
lang('Created'),
+ 'sortable' => true
+ ),
+ array(
+ 'key' => 'modified',
+ 'label' => lang('last
modified'),
+ 'sortable' => true
+ ),
+ array(
+ 'key' =>
'activity_name',
+ 'label' =>
lang('Activity'),
+ 'sortable' => true
+ ),
+ array(
+ 'key' => 'contact_name',
+ 'label' =>
lang('Contact'),
+ 'sortable' => true
+ ),
+ array(
+ 'key' => 'link',
+ 'hidden' => true
+ )
+ )
+ ),
+ );
+//_debug_array($data);
+ $parameters = array
+ (
+ 'parameter' => array
+ (
+ array
+ (
+ 'name' => 'id',
+ 'source' => 'id'
+ ),
+ )
+ );
+
+ $actions = array
+ (
+ array
+ (
+ 'my_name' => 'view',
+ 'text' => lang('view'),
+ // 'confirm_msg' => lang('do you really
want to view this entry'),
+ 'action' =>
$GLOBALS['phpgw']->link('/index.php',array
+ (
+ 'menuaction' =>
'controller.uiexample.edit',
+ )),
+ 'parameters' => $parameters
+ ),
+ array
+ (
+ 'my_name' => 'edit',
+ 'text' => lang('edit'),
+ 'confirm_msg' => lang('do you really
want to edit this entry'),
+ 'action' =>
$GLOBALS['phpgw']->link('/index.php',array
+ (
+ 'menuaction' =>
'controller.uiexample.edit',
+ )),
+ 'parameters' => $parameters
+ ),
+ array
+ (
+ 'my_name' => 'delete',
+ 'text' =>
lang('delete'),
+ 'confirm_msg' => lang('do you really
want to delete this entry'),
+ 'action' =>
$GLOBALS['phpgw']->link('/index.php',array
+ (
+ 'menuaction' =>
'controller.uiexample.delete',
+ )),
+ 'parameters' => $parameters
+ )
+ );
+
+ $data['actions'] = json_encode($actions);
+
+//_debug_array($data);die();
+ self::render_template_xsl('datatable', $data);
+ }
+
+ public function index_json()
+ {
+ $this->bo = CreateObject('booking.boapplication');
+ $this->resource_bo = CreateObject('booking.boresource');
+
+ if (
!isset($GLOBALS['phpgw_info']['user']['apps']['admin']) &&
+ $GLOBALS['phpgw']->acl->check('admin',
phpgwapi_acl::ADD, 'controller') )
+ {
+ $filters['id'] =
$this->bo->accessable_applications($GLOBALS['phpgw_info']['user']['id']);
+ }
+ $filters['status'] = 'NEW';
+ if(isset($_SESSION['showall']))
+ {
+ $filters['status'] = array('NEW',
'PENDING','REJECTED', 'ACCEPTED');
+ $testdata = phpgw::get_var('buildings', 'int', 'REQUEST',
null);
+ if ($testdata != 0)
+ {
+ $filters['building_name'] =
$this->bo->so->get_building(phpgw::get_var('buildings', 'int', 'REQUEST',
null));
+ }
+ else
+ {
+ unset($filters['building_name']);
+ }
+ $testdata2 = phpgw::get_var('activities', 'int', 'REQUEST',
null);
+ if ($testdata2 != 0)
+ {
+ $filters['activity_id'] =
$this->bo->so->get_activities(phpgw::get_var('activities', 'int', 'REQUEST',
null));
+ }
+ else
+ {
+ unset($filters['activity_id']);
+ }
+
+ }
+ else
+ {
+ if (phpgw::get_var('status') == 'none')
+ {
+ $filters['status'] = array('NEW',
'PENDING', 'REJECTED', 'ACCEPTED');
+ }
+ else
+ {
+ $filters['status'] = phpgw::get_var('status');
+ }
+ $testdata = phpgw::get_var('buildings', 'int', 'REQUEST',
null);
+ if ($testdata != 0)
+ {
+ $filters['building_name'] =
$this->bo->so->get_building(phpgw::get_var('buildings', 'int', 'REQUEST',
null));
+ }
+ else
+ {
+ unset($filters['building_name']);
+ }
+ $testdata2 = phpgw::get_var('activities', 'int', 'REQUEST',
null);
+ if ($testdata2 != 0)
+ {
+ $filters['activity_id'] =
$this->bo->so->get_activities(phpgw::get_var('activities', 'int', 'REQUEST',
null));
+ }
+ else
+ {
+ unset($filters['activity_id']);
+ }
+ }
+
+ $params = array(
+ 'start' => phpgw::get_var('startIndex', 'int',
'REQUEST', 0),
+ 'results' => phpgw::get_var('results', 'int',
'REQUEST', null),
+ 'query' => phpgw::get_var('query'),
+ 'sort' => phpgw::get_var('sort'),
+ 'dir' => phpgw::get_var('dir'),
+ 'filters' => $filters
+ );
+
+ $applications = $this->bo->so->read($params);
+
+ foreach($applications['results'] as &$application)
+ {
+ if (strstr($application['building_name'],"%"))
+ {
+ $search = array('%2C','%C3%85',
'%C3%A5', '%C3%98', '%C3%B8', '%C3%86', '%C3%A6');
+ $replace = array
(',','Å','å','Ø','ø','Æ','æ');
+ $application['building_name'] =
str_replace($search, $replace, $application['building_name']);
+ }
+
+ $application['status'] =
lang($application['status']);
+ $application['created'] =
pretty_timestamp($application['created']);
+ $application['modified'] =
pretty_timestamp($application['modified']);
+ $application['frontend_modified'] =
pretty_timestamp($application['frontend_modified']);
+ $application['resources'] =
$this->resource_bo->so->read(array('filters'=>array('id'=>$application['resources'])));
+ $application['resources'] =
$application['resources']['results'];
+ if($application['resources'])
+ {
+ $names = array();
+ foreach($application['resources'] as
$res)
+ {
+ $names[] = $res['name'];
+ }
+ $application['what'] =
$application['resources'][0]['building_name']. ' ('.join(', ', $names).')';
+ }
+ }
+ array_walk($applications["results"], array($this,
"_add_links"), "controller.uiexample.edit");
+//_debug_array($this->yui_results($applications));
+ return $this->yui_results($applications);
+ }
+
+
+ public function edit()
+ {
+ self::set_active_menu('controller::example::edit');
+ $repeat_type = $this->bo->get_rpt_type_list();
+ $repeat_day = $this->bo->get_rpt_day_list();
+
+ if(isset($_POST['save_control'])) // The user has
pressed the save button
+ {
+ if(isset($control)) // Edit control
+ {
+
$control->set_title(phpgw::get_var('title'));
+
$control->set_description(phpgw::get_var('description'));
+ $control->set_start_date( strtotime(
phpgw::get_var('start_date') ) );
+ $control->set_end_date( strtotime(
phpgw::get_var('end_date') ) );
+ $control->set_repeat_day( strtotime(
phpgw::get_var('repeat_day') ) );
+ $control->set_repeat_type( strtotime(
phpgw::get_var('repeat_type') ) );
+ $control->set_repeat_interval(
strtotime( phpgw::get_var('repeat_interval') ) );
+ $control->set_enabled( true );
+
+ $this->so->add($control);
+ }
+ else // Add new control
+ {
+
+ $control = new controller_control();
+
+
$control->set_title(phpgw::get_var('title'));
+
$control->set_description(phpgw::get_var('description'));
+ $control->set_start_date( strtotime(
phpgw::get_var('start_date') ) );
+ $control->set_end_date( strtotime(
phpgw::get_var('end_date') ) );
+ $control->set_repeat_day( strtotime(
phpgw::get_var('repeat_day') ) );
+ $control->set_repeat_type( strtotime(
phpgw::get_var('repeat_type') ) );
+ $control->set_repeat_interval(
strtotime( phpgw::get_var('repeat_interval') ) );
+ $control->set_enabled( true );
+
+ $this->so->add($control);
+ }
+ }
+
+ $control_item_array =
$this->so_control_item->get_control_item_array();
+ $control_group_array =
$this->so_control_group->get_control_group_array();
+
+
+ if($this->flash_msgs)
+ {
+ $msgbox_data =
$GLOBALS['phpgw']->common->msgbox_data($this->flash_msgs);
+ $msgbox_data =
$GLOBALS['phpgw']->common->msgbox($msgbox_data);
+ }
+
+ foreach ($control_area_array as $control_area)
+ {
+ $control_area_options = array
+ (
+ 'id' => $control_area->get_id(),
+ 'name' => $control_area->get_name()
+
+ );
+ }
+
+ foreach ($control_group_array as $control_group)
+ {
+ $control_group_options = array
+ (
+ 'id' => $control_group->get_id(),
+ 'name' => $control_group->get_name()
+
+ );
+ }
+
+ $data = array
+ (
+ 'value_id' =>
!empty($control) ? $control->get_id() : 0,
+ 'img_go_home' =>
'rental/templates/base/images/32x32/actions/go-home.png',
+ 'editable' => true,
+ 'control_item' =>
array('options' => $control_area_options),
+ 'control_group' =>
array('options' => $control_group_options),
+ );
+
+
+ $GLOBALS['phpgw_info']['flags']['app_header'] =
lang('controller') . '::' . lang('Control_item');
+
+
+
$GLOBALS['phpgw']->richtext->replace_element('what_to_do');
+
$GLOBALS['phpgw']->richtext->replace_element('how_to_do');
+ $GLOBALS['phpgw']->richtext->generate_script();
+
+
+ self::add_javascript('controller', 'yahoo',
'example_edit.js');
+ self::render_template_xsl('example_edit', $data);
+ }
+
+
+ public function separate_tabs()
+ {
+
self::set_active_menu('controller::example::separate_tabs');
+
+ $type = phpgw::get_var('type', 'string', 'REQUEST', null);
+
+ $tabs = array();
+ $tabs[] = array(
+ 'label' => lang('Your preferences'),
+ 'link' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'controller.uiexample.separate_tabs', 'type' => 'user'))
+ );
+ $tabs[] = array(
+ 'label' => lang('Default preferences'),
+ 'link' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'controller.uiexample.separate_tabs', 'type' => 'default'))
+ );
+ $tabs[] = array(
+ 'label' => lang('Forced preferences'),
+ 'link' =>
$GLOBALS['phpgw']->link('/index.php', array('menuaction' =>
'controller.uiexample.separate_tabs', 'type' => 'forced'))
+ );
+
+ switch($type)
+ {
+ case 'default':
+ $selected = 1;
+ $resource_id = 81;
+ break;
+ case 'forced':
+ $selected = 2;
+ $resource_id = 46;
+ break;
+ case 'user':
+ default:
+ $selected = 0;
+ $resource_id = 80;
+ }
+
+ $add_document_link =
$GLOBALS['phpgw']->link('/index.php', array('menuaction'=>
'controller.uiexample.index') );
+ $resource = array('id' => $resource_id,
'add_document_link' => $add_document_link, 'permission' => array('write' =>
true ) );
+
+ $data = array
+ (
+ 'tabs' =>
$GLOBALS['phpgw']->common->create_tabs($tabs, $selected),
+ 'resource' => $resource
+ );
+ self::add_javascript('controller', 'yahoo',
'example_separate_tabs.js');
+ self::render_template_xsl('example_separate_tabs',
$data);
+ }
+
+
+ public function delete()
+ {
+ return 'deleted';
+ }
+
+ public function js_poll()
+ {
+ if($poll = phpgw::get_var('poll'))
+ {
+ return $poll;
+ }
+ return 'hello world';
+ }
+
+ public function query()
+ {
+ var_dump("Er i uicontrol");
+
+ }
+ }
Added: trunk/controller/js/yahoo/example_edit.js
===================================================================
--- trunk/controller/js/yahoo/example_edit.js (rev 0)
+++ trunk/controller/js/yahoo/example_edit.js 2011-09-20 07:41:12 UTC (rev
7664)
@@ -0,0 +1,24 @@
+ /* Specific js-code for controller::item
+ *
+ */
+
+alert('dette er respons fra "controller/js/yahoo/controller.item.js"');
+
+/*
+ this.get_some_feedback = function()
+ {
+ var callback = {success: function(o){
+ feedback =
JSON.parse(o.responseText);
+ // console.log(feedback);
+ alert(feedback);
+ },
+ failure:
function(o){window.alert('Server or your connection is dead.')},
+ timeout: 10000
+ };
+ var oArgs = {menuaction:'controller.uiexample.js_poll',poll:''};
+ var strURL = phpGWLink('index.php', oArgs, true);
+ var request = YAHOO.util.Connect.asyncRequest('POST', strURL,
callback);
+ }
+
+ get_some_feedback();
+*/
Added: trunk/controller/templates/base/example_edit.xsl
===================================================================
--- trunk/controller/templates/base/example_edit.xsl
(rev 0)
+++ trunk/controller/templates/base/example_edit.xsl 2011-09-20 07:41:12 UTC
(rev 7664)
@@ -0,0 +1,80 @@
+<!-- item -->
+
+<xsl:template match="data" xmlns:php="http://php.net/xsl">
+
+<xsl:call-template name="yui_booking_i18n"/>
+<div class="identifier-header">
+<h1><img src="{img_go_home}" />
+ <xsl:value-of select="php:function('lang', 'Control_item')" />
+</h1>
+</div>
+
+<div class="yui-content">
+ <div id="details">
+ <form action="#" method="post">
+ <input type="hidden" name="id" value =
"{value_id}">
+ </input>
+ <dl class="proplist-col">
+ <dt>
+ <label
for="title">Tittel</label>
+ </dt>
+ <dd>
+ <input type="text" name="title"
id="title" value="" />
+ </dd>
+ <dt>
+ <label
for="required">Obligatorisk</label>
+ </dt>
+ <dd>
+ <input type="checkbox" value=""
/>
+ </dd>
+ <dt>
+ <label for="what_to_do">Hva
skal utføres</label>
+ </dt>
+ <dd>
+ <textarea id="what_to_do"
rows="5" cols="60"></textarea>
+ </dd>
+ <dt>
+ <label
for="how_to_do">Utførelsesbeskrivelse</label>
+ </dt>
+ <dd>
+ <textarea id="how_to_do"
rows="5" cols="60"></textarea>
+ </dd>
+ <dt>
+ <label
for="control_group">Kontrollgruppe</label>
+ </dt>
+ <dd>
+ <select id="control_group"
name="control_group">
+ <xsl:apply-templates
select="control_group/options"/>
+ </select>
+ </dd>
+ <dt>
+ <label
for="control_area">Kontrolltype</label>
+ </dt>
+ <dd>
+ <select id="control_area"
name="control_area">
+ <xsl:apply-templates
select="control_area/options"/>
+ </select>
+ </dd>
+ </dl>
+
+ <div class="form-buttons">
+ <xsl:variable
name="lang_save"><xsl:value-of select="php:function('lang', 'save')"
/></xsl:variable>
+ <input type="submit"
name="save_control" value="{$lang_save}" title = "{$lang_save}">
+ </input>
+ </div>
+
+ </form>
+
+ </div>
+ </div>
+</xsl:template>
+
+<xsl:template match="options">
+ <option value="{id}">
+ <xsl:if test="selected != 0">
+ <xsl:attribute name="selected" value="selected" />
+ </xsl:if>
+ <xsl:value-of disable-output-escaping="yes" select="name"/>
+ </option>
+</xsl:template>
+
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Fmsystem-commits] [7664] controller: separate example-code,
Sigurd Nes <=