![]() |
Xataface Depselect Module 0.1
Dependent Select List Widget for Xataface Forms
|
00001 <?php 00002 import('Dataface/FormTool/select.php'); 00003 /* 00004 * Xataface DepSelect Module 00005 * Copyright (C) 2011 Steve Hannah <steve@weblite.ca> 00006 * 00007 * This library is free software; you can redistribute it and/or 00008 * modify it under the terms of the GNU Library General Public 00009 * License as published by the Free Software Foundation; either 00010 * version 2 of the License, or (at your option) any later version. 00011 * 00012 * This library is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 * Library General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Library General Public 00018 * License along with this library; if not, write to the 00019 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, 00020 * Boston, MA 02110-1301, USA. 00021 * 00022 */ 00035 class Dataface_FormTool_depselect extends Dataface_FormTool_select { 00036 00048 function &buildWidget(&$record, &$field, &$form, $formFieldName, $new=false){ 00049 $el = parent::buildWidget($record, $field, $form, $formFieldName, $new); 00050 $mt = Dataface_ModuleTool::getInstance(); 00051 $mod = $mt->loadModule('modules_depselect'); 00052 $atts = $el->getAttributes(); 00053 if ( !@$atts['class'] ) $atts['class'] = ''; 00054 $atts['class'] .= ' xf-depselect'; 00055 if ( !@$atts['data-xf-table'] ){ 00056 $atts['data-xf-table'] = $field['tablename']; 00057 } 00058 $targetTable = Dataface_Table::loadTable($field['widget']['table']); 00059 if ( PEAR::isError($targetTable) ){ 00060 error_log("Your field $formFieldName is missing the widget:table directive or the table does not exist."); 00061 throw new Exception("Your field $formFieldName is missing the widget:table directive or the table does not exist."); 00062 } 00063 $targetPerms = $targetTable->getPermissions(); 00064 if ( @$targetPerms['new'] ){ 00065 $atts['data-xf-depselect-options-table'] = $field['widget']['table']; 00066 } 00067 $atts['df:cloneable'] = 1; 00068 00069 00070 00071 $jt = Dataface_JavascriptTool::getInstance(); 00072 $jt->addPath(dirname(__FILE__).'/js', $mod->getBaseURL().'/js'); 00073 00074 $ct = Dataface_CSSTool::getInstance(); 00075 $ct->addPath(dirname(__FILE__).'/css', $mod->getBaseURL().'/css'); 00076 00077 // Add our javascript 00078 $jt->import('xataface/widgets/depselect.js'); 00079 00080 $filters = array(); 00081 if ( @$field['widget']['filters'] and is_array($field['widget']['filters'])){ 00082 foreach ($field['widget']['filters'] as $key=>$val){ 00083 $filters[] = urlencode($key).'='.urlencode($val); 00084 } 00085 } 00086 00087 $atts['data-xf-depselect-filters'] = implode('&', $filters); 00088 00089 00090 00091 if ( @$field['widget']['nomatch'] ){ 00092 $atts['data-xf-depselect-nomatch'] = $field['widget']['nomatch']; 00093 } 00094 00095 $el->setAttributes($atts); 00096 00097 return $el; 00098 } 00099 00100 00101 }