Xataface Depselect Module  0.1
Dependent Select List Widget for Xataface Forms
 All Data Structures Files Functions Pages
/Volumes/Windows VMS/sites/chichaku/modules/depselect/widget.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Xataface DepSelect Module
4  * Copyright (C) 2011 Steve Hannah <steve@weblite.ca>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the
18  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
19  * Boston, MA 02110-1301, USA.
20  *
21  */
35 
47  function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){
48  $factory = Dataface_FormTool::factory();
49  $mt = Dataface_ModuleTool::getInstance();
50  $mod = $mt->loadModule('modules_depselect');
51  //$atts = $el->getAttributes();
52  $widget =& $field['widget'];
53  $atts = array();
54  if ( !@$atts['class'] ) $atts['class'] = '';
55  $atts['class'] .= ' xf-depselect';
56  if ( !@$atts['data-xf-table'] ){
57  $atts['data-xf-table'] = $field['tablename'];
58  }
59  $targetTable = Dataface_Table::loadTable($field['widget']['table']);
60  if ( PEAR::isError($targetTable) ){
61  error_log("Your field $formFieldName is missing the widget:table directive or the table does not exist.");
62  throw new Exception("Your field $formFieldName is missing the widget:table directive or the table does not exist.");
63  }
64  $targetPerms = $targetTable->getPermissions();
65  $atts['data-xf-depselect-options-table'] = $field['widget']['table'];
66  if ( @$targetPerms['new'] ){
67  $atts['data-xf-depselect-perms-new'] = 1;
68  }
69  $atts['df:cloneable'] = 1;
70 
71 
72  $jt = Dataface_JavascriptTool::getInstance();
73  $jt->addPath(dirname(__FILE__).'/js', $mod->getBaseURL().'/js');
74 
75  $ct = Dataface_CSSTool::getInstance();
76  $ct->addPath(dirname(__FILE__).'/css', $mod->getBaseURL().'/css');
77 
78  // Add our javascript
79  $jt->import('xataface/widgets/depselect.js');
80 
81  $filters = array();
82  if ( @$field['widget']['filters'] and is_array($field['widget']['filters'])){
83  foreach ($field['widget']['filters'] as $key=>$val){
84  $filters[] = urlencode($key).'='.urlencode($val);
85  }
86  }
87 
88  $atts['data-xf-depselect-filters'] = implode('&', $filters);
89 
90 
91 
92  if ( @$field['widget']['nomatch'] ){
93  $atts['data-xf-depselect-nomatch'] = $field['widget']['nomatch'];
94  }
95 
96  //$el->setAttributes($atts);
97  $el = $factory->addElement('text', $formFieldName, $widget['label'], $atts);
98  if ( PEAR::isError($el) ) throw new Exception($el->getMessage(), $el->getCode());
99 
100 
101  return $el;
102  }
103 
104 
105 }