function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $formTool =& Dataface_FormTool::getInstance(); $factory =& Dataface_FormTool::factory(); if (isset($field['fields'])) { $els = array(); foreach (array_keys($field['fields']) as $field_key) { $els[] = $formTool->buildWidget($record, $field['fields'][$field_key], $factory, $field['fields'][$field_key]['name']); } $el =& $factory->addGroup($els, $field['name'], $field['widget']['label']); } else { $el =& $factory->addElement('text', $field['name'], $widget['label']); } if (!@$field['widget']['layout']) { $field['widget']['layout'] = 'table'; } if (!@$field['widget']['layout']) { $field['widget']['columns'] = 1; } if (!@$field['widget']['separator']) { $field['widget']['separator'] = '<br />'; } $el->setFieldDef($field); return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { /* * * This field uses a table widget. * */ $table =& $record->_table; $formTool =& Dataface_FormTool::getInstance(); $factory =& Dataface_FormTool::factory(); $widget =& $field['widget']; $el =& $factory->addElement('table', $formFieldName, $widget['label']); if (isset($widget['fields'])) { $widget_fields =& $widget['fields']; foreach ($widget_fields as $widget_field) { $widget_field =& Dataface_Table::getTableField($widget_field, $this->db); if (PEAR::isError($widget_field)) { return $widget_field; } $widget_widget = $formTool->buildWidget($record, $widget_field, $factory, $widget_field['name']); $el->addField($widget_widget); } } else { if (isset($field['fields'])) { foreach (array_keys($field['fields']) as $field_key) { $widget_widget = $formTool->buildWidget($record, $field['fields'][$field_key], $factory, $field['fields'][$field_key]['name']); $el->addField($widget_widget); unset($widget_widget); } } } return $el; }
function &buildWidget(&$record, &$field, $form, $formFieldName, $new = false) { $widget =& $field['widget']; $factory =& Dataface_FormTool::factory(); $el =& $factory->addElement('date', $formFieldName, $widget['label'], $widget); return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $table =& $record->_table; $widget =& $field['widget']; if (!@$widget['repeat']) { $widget['repeat'] = 1; } $factory =& Dataface_FormTool::factory(); $attributes = array('class' => $widget['class'], 'id' => $field['name']); if ($field['repeat']) { $attributes['multiple'] = true; $attributes['size'] = 5; } $options =& Dataface_FormTool::getVocabulary($record, $field); if (!isset($options)) { $options = array(); } if ($record and $record->val($field['name'])) { $vals = $record->val($field['name']); if (is_array($vals)) { foreach ($vals as $thisval) { if (!isset($options[$thisval])) { $options[$thisval] = $thisval; } } } } $el =& $factory->addElement('advmultiselect', $formFieldName, $widget['label'], $options, $attributes); //$el->setFieldDef($field); //return $el; $el->setButtonAttributes('moveup', 'class=inputCommand'); $el->setButtonAttributes('movedown', 'class=inputCommand'); return $el; }
/** * Defines how a radio button widget should be built. * * @param Dataface_Record $record The Dataface_Record that is being edited. * @param array &$field The field configuration data structure that the widget is being generated for. * @param HTML_QuickForm The form to which the field is to be added. * @param string $formFieldName The name of the field in the form. * @param boolean $new Whether this widget is being built for a new record form. * @return HTML_QuickForm_element The element that can be added to a form. * */ function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $widget =& $field['widget']; if (!@$widget['separator']) { $widget['separator'] = '<br />'; } if (isset($field['vocabulary']) and $field['vocabulary']) { $radios = array(); $dummyForm = new HTML_QuickForm(); $options =& Dataface_FormTool::getVocabulary($record, $field); $options__classes = Dataface_FormTool::getVocabularyClasses($record, $field); // CSS classes foreach ($options as $opt_val => $opt_text) { if ($opt_val === '') { continue; } $radios[] =& $dummyForm->createElement('radio', null, null, $opt_text, $opt_val, array('class' => 'radio-of-' . $field['name'] . ' ' . @$options__classes[$opt_val])); } $factory =& Dataface_FormTool::factory(); $el =& $factory->addGroup($radios, $field['name'], $widget['label']); } else { error_log("Your field {$formFieldName} is missing the vocabulary directive."); throw new Exception("Your field {$formFieldName} is missing the vocabulary directive."); } return $el; }
/** * Defines how a geopicker widget should be built. * * @param Dataface_Record $record The Dataface_Record that is being edited. * @param array &$field The field configuration data structure that the widget is being generated for. * @param HTML_QuickForm The form to which the field is to be added. * @param string $formFieldName The name of the field in the form. * @param boolean $new Whether this widget is being built for a new record form. * @return HTML_QuickForm_element The element that can be added to a form. * */ function &buildWidget($record, &$field, $form, $formFieldName, $new = false) { $factory = Dataface_FormTool::factory(); $mt = Dataface_ModuleTool::getInstance(); $mod = $mt->loadModule('modules_geopicker'); $widget =& $field['widget']; $atts = array(); if (!@$atts['class']) { $atts['class'] = ''; } $atts['class'] .= ' xf-geopicker'; $atts['df:cloneable'] = 1; $perms = $record->getPermissions(array('field' => $field['name'])); $noEdit = ($new and !@$perms['new']) or !$new and !@$perms['edit']; if ($noEdit) { $atts['data-geopicker-read-only'] = "1"; } $mod->registerPaths(); // Add our javascript Dataface_JavascriptTool::getInstance()->import('xataface/modules/geopicker/widgets/geopicker.js'); $el = $factory->addElement('text', $formFieldName, $widget['label'], $atts); if (PEAR::isError($el)) { throw new Exception($el->getMessage(), $el->getCode()); } return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $widget =& $field['widget']; $options =& Dataface_FormTool::getVocabulary($record, $field); $factory = Dataface_FormTool::factory(); $el = $factory->addElement('autocomplete', $formFieldName, $widget['label'], array('class' => $widget['class'], 'id' => $field['name'])); $el->setOptions($options); return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $widget =& $field['widget']; $factory =& Dataface_FormTool::factory(); $widget['record'] =& $record; $el =& $factory->addElement('portal', $formFieldName, $widget['label']); $el->init_portal($widget); return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $factory =& Dataface_FormTool::factory(); $el =& $factory->addElement('hidden', $field['name']); if (PEAR::isError($el)) { throw new Exception("Failed to get element for field {$field['name']} of table " . $record->_table->tablename . "\n" . "The error returned was " . $el->getMessage(), E_USER_ERROR); } $el->setFieldDef($field); return $el; }
/** * Defines how a depselect widget should be built. * * @param Dataface_Record $record The Dataface_Record that is being edited. * @param array &$field The field configuration data structure that the widget is being generated for. * @param HTML_QuickForm The form to which the field is to be added. * @param string $formFieldName The name of the field in the form. * @param boolean $new Whether this widget is being built for a new record form. * @return HTML_QuickForm_element The element that can be added to a form. * */ function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $factory = Dataface_FormTool::factory(); $mt = Dataface_ModuleTool::getInstance(); $mod = $mt->loadModule('modules_depselect'); //$atts = $el->getAttributes(); $widget =& $field['widget']; $atts = array(); if (!@$atts['class']) { $atts['class'] = ''; } $atts['class'] .= ' xf-depselect'; if (!@$atts['data-xf-table']) { $atts['data-xf-table'] = $field['tablename']; } $targetTable = Dataface_Table::loadTable($field['widget']['table']); if (PEAR::isError($targetTable)) { error_log("Your field {$formFieldName} is missing the widget:table directive or the table does not exist."); throw new Exception("Your field {$formFieldName} is missing the widget:table directive or the table does not exist."); } $targetPerms = $targetTable->getPermissions(); $atts['data-xf-depselect-options-table'] = $field['widget']['table']; if (@$targetPerms['new']) { $atts['data-xf-depselect-perms-new'] = 1; } $atts['df:cloneable'] = 1; $jt = Dataface_JavascriptTool::getInstance(); $jt->addPath(dirname(__FILE__) . '/js', $mod->getBaseURL() . '/js'); $ct = Dataface_CSSTool::getInstance(); $ct->addPath(dirname(__FILE__) . '/css', $mod->getBaseURL() . '/css'); // Add our javascript $jt->import('xataface/widgets/depselect.js'); $filters = array(); if (@$field['widget']['filters'] and is_array($field['widget']['filters'])) { foreach ($field['widget']['filters'] as $key => $val) { $filters[] = urlencode($key) . '=' . urlencode($val); } } $atts['data-xf-depselect-filters'] = implode('&', $filters); if (@$field['widget']['nomatch']) { $atts['data-xf-depselect-nomatch'] = $field['widget']['nomatch']; } if (@$field['widget']['dialogSize']) { $atts['data-xf-depselect-dialogSize'] = $field['widget']['dialogSize']; } if (@$field['widget']['dialogMargin']) { $atts['data-xf-depselect-dialogMargin'] = $field['widget']['dialogMargin']; } //$el->setAttributes($atts); $el = $factory->addElement('depselect', $formFieldName, $widget['label'], $atts); if (PEAR::isError($el)) { throw new Exception($el->getMessage(), $el->getCode()); } return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $factory =& Dataface_FormTool::factory(); $el =& $factory->addElement('hidden', $field['name']); if (PEAR::isError($el)) { echo "Failed to get element for field {$field['name']} of table " . $record->_table->tablename; echo "The error returned was " . $el->getMessage(); echo Dataface_Error::printStackTrace(); } $el->setFieldDef($field); return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { /* * This field uses a calendar widget */ $widget =& $field['widget']; if (!@$widget['lang']) { $widget['lang'] = Dataface_Application::getInstance()->_conf['lang']; } $factory =& Dataface_FormTool::factory(); $el =& $factory->addElement('calendar', $formFieldName, $widget['label'], null, $widget); //$el->setProperties($widget); return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { /* * This field uses a calendar widget */ $widget =& $field['widget']; $factory =& Dataface_FormTool::factory(); $el =& $factory->addElement('lookup', $formFieldName, $widget['label']); if (PEAR::isError($el)) { return $el; } $el->setProperties($widget); return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { /* * This field uses a calendar widget */ $widget =& $field['widget']; $factory =& Dataface_FormTool::factory(); $el =& $factory->addElement('yui_autocomplete', $formFieldName, $widget['label']); $el->setProperties($widget); if (@$field['vocabulary']) { $el->options = $record->_table->getValuelist($field['vocabulary']); $el->vocabularyName = $field['vocabulary']; $el->updateAttributes(array('df:vocabulary' => $el->vocabularyName)); } else { if (isset($widget['datasource'])) { $datasource =& $widget['datasource']; if (isset($datasource['url'])) { $el->datasourceUrl = $datasource['url']; $el->updateAttributes(array('df:datasource' => $el->datasourceUrl)); if (!isset($datasource['resultNode'])) { $datasource['resultNode'] = 'Result'; } $el->resultNode = $datasource['resultNode']; $el->updateAttributes(array('df:resultNode' => $el->resultNode)); if (!isset($datasource['fieldname'])) { $datasource['fieldname'] = 'df:title'; } $el->queryKeyNode = $datasource['fieldname']; $el->updateAttributes(array('df:queryKeyNode' => $el->queryKeyNode)); if (!@$datasource['other_fieldnames']) { $el->additionalNodes = array(); } else { $el->additionalNodes = array_map('trim', explode(',', $datasource['other_fieldnames'])); } $el->updateAttributes(array('df:additionalNodes' => implode(',', $el->additionalNodes))); if (!@$datasource['scriptQueryParam']) { $datasource['scriptQueryParam'] = '-search'; } $el->scriptQueryParam = $datasource['scriptQueryParam']; $el->updateAttributes(array('df:scriptQueryParam' => $el->scriptQueryParam)); } } } if (@$field['yui_autocomplete'] and is_array($field['yui_autocomplete'])) { $el->updateAttributes(array('data-xf-max-results-displayed' => $field['yui_autocomplete']['maxResultsDisplayed'])); } return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { if (is_string($field)) { echo Dataface_Error::printStackTrace(); } $table =& $record->_table; $widget =& $field['widget']; $factory =& Dataface_FormTool::factory(); $el =& $factory->addElement('htmlarea', $formFieldName, $widget['label'], array('class' => $widget['class'], 'id' => $field['name'])); if (method_exists($el, 'setWysiwygOptions')) { $el->setWysiwygOptions($widget); if (isset($widget['editor'])) { $el->editorName = $widget['editor']; } } return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { if (is_string($field)) { throw new Exception("buildWidget expects field to be a structure but recieved a string: {$field}", E_USER_ERROR); } $table =& $record->_table; $widget =& $field['widget']; $factory =& Dataface_FormTool::factory(); $el =& $factory->addElement('htmlarea', $formFieldName, $widget['label'], array('class' => $widget['class'], 'id' => $field['name'])); if (method_exists($el, 'setWysiwygOptions')) { $el->setWysiwygOptions($widget); if (isset($widget['editor'])) { $el->editorName = $widget['editor']; } } return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $table =& $record->_table; $widget =& $field['widget']; if (!@$widget['separator']) { $widget['separator'] = '<br />'; } $factory =& Dataface_FormTool::factory(); $boxes = array(); if (@$field['vocabulary']) { $options =& Dataface_FormTool::getVocabulary($record, $field); $options__classes = Dataface_FormTool::getVocabularyClasses($record, $field); } if ($record and $record->val($field['name'])) { $vals = $record->val($field['name']); if (is_array($vals)) { foreach ($vals as $thisval) { if (!isset($options[$thisval])) { $options[$thisval] = $thisval; } } } } $dummyForm = new HTML_QuickForm(); foreach ($options as $opt_val => $opt_text) { if ($opt_val === '') { if (!(@$field['validators'] && @$field['validators']['required'])) { //$boxes[] = $dummyForm->createElement('radio', $field['name'], null , 'None', '', array('class'=>'radio-of-'.$field['name'].' '.@$options__classes[$opt_val])); } } else { $boxes[] =& $dummyForm->createElement('radio', $field['name'], null, $opt_text, $opt_val, array('class' => 'radio-of-' . $field['name'] . ' ' . @$options__classes[$opt_val])); } } $el =& $factory->addGroup($boxes, $field['name'], $widget['label']); return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $table =& $record->_table; $widget =& $field['widget']; $factory = Dataface_FormTool::factory(); $attributes = array('class' => $widget['class'], 'id' => $field['name']); if ($field['repeat']) { $attributes['multiple'] = true; $attributes['size'] = 5; } $options = $record->_table->getValuelist($field['vocabulary']); //Dataface_FormTool::getVocabulary($record, $field); if (!isset($options)) { $options = array(); } $emptyOpt = array('' => df_translate('scripts.GLOBAL.FORMS.OPTION_PLEASE_SELECT', "Please Select...")); $opts = $emptyOpt; if ($record and $record->val($field['name'])) { if (!@$field['repeat'] and !isset($options[$record->strval($field['name'])])) { $opts[$record->strval($field['name'])] = $record->strval($field['name']); } else { if (@$field['repeat']) { $vals = $record->val($field['name']); if (is_array($vals)) { foreach ($vals as $thisval) { if (!isset($options[$thisval])) { $opts[$thisval] = $thisval; } } } } } } foreach ($options as $kopt => $opt) { $opts[$kopt] = $opt; } $el = $factory->addElement('select', $formFieldName, $widget['label'], $opts, $attributes); // Now to make it editable if (@$field['vocabulary']) { try { $rel =& Dataface_ValuelistTool::getInstance()->asRelationship($table, $field['vocabulary']); if ($rel and !PEAR::isError($rel)) { $dtable = Dataface_Table::loadTable($rel->getDomainTable()); if ($dtable and !PEAR::isError($dtable)) { $perms = $dtable->getPermissions(); if (@$perms['new']) { $fields =& $rel->fields(); if (count($fields) > 1) { $valfield = $fields[1]; $keyfield = $fields[0]; } else { $valfield = $fields[0]; $keyfield = $fields[0]; } if (strpos($valfield, '.') !== false) { list($tmp, $valfield) = explode('.', $valfield); } if (strpos($keyfield, '.') !== false) { list($tmp, $keyfield) = explode('.', $keyfield); } $suffix = '<script type="text/javascript" src="' . DATAFACE_URL . '/js/jquery-ui-1.7.2.custom.min.js"></script>'; $suffix .= '<script type="text/javascript" src="' . DATAFACE_URL . '/js/RecordDialog/RecordDialog.js"></script>'; $suffix .= '<a href="#" onclick="return false" id="' . htmlspecialchars($field['name']) . '-other">Other..</a>'; $suffix .= '<script> $(\'head\').append(\'<link rel="stylesheet" type="text/css" href="\'+DATAFACE_URL+\'/css/smoothness/jquery-ui-1.7.2.custom.css"/>\'); jQuery(document).ready(function($){ $("#' . $field['name'] . '-other").each(function(){ var tablename = "' . addslashes($dtable->tablename) . '"; var valfld = ' . json_encode($valfield) . '; var keyfld = ' . json_encode($keyfield) . '; var fieldname = ' . json_encode($field['name']) . '; var btn = this; $(this).RecordDialog({ table: tablename, callback: function(data){ var key = data[keyfld]; var val = data[valfld]; $("#"+fieldname).append(\'<option value="\'+key+\'">\'+val+\'</option>\'); $("#"+fieldname).val(key); } }); }); }); </script> '; $widget['suffix'] = $suffix; } } } } catch (Exception $ex) { error_log($ex->getMessage()); } } //$el->setFieldDef($field); //return $el; return $el; }
/** * @brief Builds a widget that can be added to a form. This will delegate * to the WidgetHandler::buildWidget() method if defined for the field's widget * type. * * @param Dataface_Record &$record The Dataface Record that this widget * is to be editing. * @param array &$field The field definition. * @param HTML_QuickForm The form to which the widget will be added. * @param string $formFieldName The name of the field on the form. * @returns HTML_QuickForm_element */ function &buildWidget($record, &$field, $form, $formFieldName, $new = false, $permissions = null) { $table =& $record->_table; $widget =& $field['widget']; if (!isset($permissions)) { //$permissions =& $record->getPermissions(array('field'=>$field['name'])); $permissions = Dataface_PermissionsTool::ALL(); // reference to widget descriptor array } $pt =& Dataface_PermissionsTool::getInstance(); // Reference to permissions tool to operate on $permissions $widgetHandler =& $this->getWidgetHandler($widget['type']); if (isset($widgetHandler) and method_exists($widgetHandler, 'buildWidget')) { $el =& $widgetHandler->buildWidget($record, $field, $form, $formFieldName, $new); } else { $factory =& Dataface_FormTool::factory(); // A dummy HTML_QuickForm used as a factory to create temporary elements. // Reference to the table object. $el =& $factory->addElement($widget['type'], $formFieldName, $widget['label'], array('class' => $widget['class'], 'id' => $formFieldName)); } if (PEAR::isError($el)) { throw new Exception($el->toString(), E_USER_ERROR); } $el->setFieldDef($field); if (isset($record) && $record && $record->_table->hasField($field['name'])) { if ($link = $record->getLink($field['name'])) { $el->setProperty('link', $link); } $el->setProperty('record_url', $record->getURL()); } $atts = $el->getAttributes(); if (!is_array($atts)) { $atts = array(); } $atts = array_merge($atts, $field['widget']['atts']); foreach ($atts as $k => $v) { if (strpos($k, 'data-xf-override-') === 0) { $atts[substr($k, 17)] = $v; } } if (!isset($atts['data-xf-field'])) { $atts['data-xf-field'] = $field['name']; } $el->setAttributes($atts); if ($new and !$pt->checkPermission('new', $permissions)) { $el->freeze(); } else { if (!$new and !$pt->checkPermission('edit', $permissions)) { $el->freeze(); } } /* // Deal with permissions on this field. if ( $pt->view($permissions) and !$pt->edit($permissions) ){ if ( !($new && $pt->checkPermission('new', $permissions)) ){ $el->freeze(); } } */ $el->record =& $record; $form->addElement($el); /* * * If there are any validation options set for the field, we must add these rules to the quickform * element. * */ $validators = $field['validators']; foreach ($validators as $vname => $validator) { /* * * $validator['arg'] would be specified in the INI file. * Example ini file listing: * ------------------------- * [FirstName] * widget:label = First name * widget:description = Enter your first name * validators:regex = "/[0-9a-zA-Z/" * * This would result in $validator['arg'] = "/[0-9a-zA-Z/" in this section * and $vname == "regex". Hence it would mean that a regular expression validator * is being placed on this field so that only Alphanumeric characters are accepted. * Please see documentation for HTML_QuickForm PEAR class for more information * about QuickForm validators. * */ if ($vname == 'required' && $widget['type'] == 'file') { continue; } $form->addRule($formFieldName, $validator['message'], $vname, @$validator['arg'], $widget['type'] == 'htmlarea' ? null : 'client'); } $this->pullField($record, $field, $form, $formFieldName, $new); $el->_persistantFreeze = true; return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $table =& $record->_table; $widget =& $field['widget']; if (!@$widget['separator']) { $widget['separator'] = '<br />'; } $factory =& Dataface_FormTool::factory(); if (isset($field['repeat']) and $field['repeat'] and isset($field['vocabulary']) and $field['vocabulary'] or isset($field['transient']) and isset($field['relationship'])) { $boxes = array(); $options = array(); if (@$field['vocabulary']) { $options =& Dataface_FormTool::getVocabulary($record, $field); $options__classes = Dataface_FormTool::getVocabularyClasses($record, $field); } else { if (isset($field['relationship'])) { $relationship =& $record->_table->getRelationship($field['relationship']); $options = $relationship->getAddableValues($record); $options__classes = array(); // Now let's add the ability to add an option that isn't already there // but only if the user has permission if (!@$widget['suffix']) { $widget['suffix'] = ''; } $dtable =& Dataface_Table::loadTable($relationship->getDomainTable()); if (!PEAR::isError($dtable) and $record->checkPermission('add new related record', array('relationship' => $relationship->getName()))) { import('Dataface/JavascriptTool.php'); $jt = Dataface_JavascriptTool::getInstance(); $jt->import('xataface/widgets/checkbox.js'); // $suffix = '<script type="text/javascript" src="'.DATAFACE_URL.'/js/jquery-ui-1.7.2.custom.min.js"></script>'; //$suffix .= '<script type="text/javascript" src="'.DATAFACE_URL.'/js/RecordDialog/RecordDialog.js"></script>'; $suffix = '<a class="xf-checkbox-widget-other-link" href="#" onclick="return false" id="' . df_escape($field['name']) . '-other" data-relationship-name="' . df_escape($relationship->getName()) . '" data-table-name="' . df_escape($dtable->tablename) . '" data-field-name="' . df_escape($field['name']) . '" data-keys="' . df_escape(json_encode(array_keys($dtable->keys()))) . '" >Other..</a>'; $widget['suffix'] = $suffix; } } } if ($record and $record->val($field['name'])) { $vals = $record->val($field['name']); if (is_array($vals)) { foreach ($vals as $thisval) { if (!isset($options[$thisval])) { $options[$thisval] = $thisval; } } } } $dummyForm = new HTML_QuickForm(); foreach ($options as $opt_val => $opt_text) { if ($opt_val === '') { continue; } $boxes[] =& $dummyForm->createElement('checkbox', $opt_val, null, $opt_text, array('class' => 'checkbox-of-' . $field['name'] . ' ' . @$options__classes[$opt_val])); //$boxes[count($boxes)-1]->setValue($opt_val); } $el =& $factory->addGroup($boxes, $field['name'], $widget['label']); } else { $el =& $factory->addElement('advcheckbox', $formFieldName, $widget['label']); if ($field['vocabulary']) { $yes = ''; $no = ''; if ($table->isYesNoValuelist($field['vocabulary'], $yes, $no)) { $el->setValues(array($no, $yes)); } } } return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $table =& $record->_table; $widget =& $field['widget']; if (!@$widget['separator']) { $widget['separator'] = '<br />'; } $factory =& Dataface_FormTool::factory(); if (isset($field['repeat']) and $field['repeat'] and isset($field['vocabulary']) and $field['vocabulary'] or isset($field['transient']) and isset($field['relationship'])) { $boxes = array(); $options = array(); if (@$field['vocabulary']) { $options =& Dataface_FormTool::getVocabulary($record, $field); $options__classes = Dataface_FormTool::getVocabularyClasses($record, $field); } else { if (isset($field['relationship'])) { $relationship =& $record->_table->getRelationship($field['relationship']); $options = $relationship->getAddableValues($record); $options__classes = array(); // Now let's add the ability to add an option that isn't already there // but only if the user has permission if (!@$widget['suffix']) { $widget['suffix'] = ''; } $dtable =& Dataface_Table::loadTable($relationship->getDomainTable()); if (!PEAR::isError($dtable) and $record->checkPermission('add new related record', array('relationship' => $relationship->getName()))) { $suffix = '<script type="text/javascript" src="' . DATAFACE_URL . '/js/jquery-ui-1.7.2.custom.min.js"></script>'; $suffix .= '<script type="text/javascript" src="' . DATAFACE_URL . '/js/RecordDialog/RecordDialog.js"></script>'; $suffix .= '<a href="#" onclick="return false" id="' . htmlspecialchars($field['name']) . '-other">Other..</a>'; $suffix .= '<script> $(\'head\').append(\'<link rel="stylesheet" type="text/css" href="\'+DATAFACE_URL+\'/css/smoothness/jquery-ui-1.7.2.custom.css"/>\'); jQuery(document).ready(function($){ $("#' . $field['name'] . '-other").each(function(){ var tablename = "' . addslashes($dtable->tablename) . '"; var fldname = "' . addslashes(htmlspecialchars($field['name'])) . '"; var keys = ' . json_encode(array_keys($dtable->keys())) . '; var btn = this; $(this).RecordDialog({ table: tablename, callback: function(data){ var val = []; for ( var i=0; i<keys.length; i++){ val.push(encodeURIComponent(keys[i])+\'=\'+encodeURIComponent(data[keys[i]])); } val = val.join(\'&\'); fldname = tablename+\'[\'+val+\']\'; $(btn).before(\'<input type="checkbox" name="\'+fldname+\'" value="\'+val+\'" checked="1"/>\'+data["__title__"]+\'<br/>\'); } }); }); }); </script> '; $widget['suffix'] = $suffix; } } } if ($record and $record->val($field['name'])) { $vals = $record->val($field['name']); if (is_array($vals)) { foreach ($vals as $thisval) { if (!isset($options[$thisval])) { $options[$thisval] = $thisval; } } } } $dummyForm = new HTML_QuickForm(); foreach ($options as $opt_val => $opt_text) { if (!$opt_val) { continue; } $boxes[] =& $dummyForm->createElement('checkbox', $opt_val, null, $opt_text, array('class' => 'checkbox-of-' . $field['name'] . ' ' . @$options__classes[$opt_val])); //$boxes[count($boxes)-1]->setValue($opt_val); } $el =& $factory->addGroup($boxes, $field['name'], $widget['label']); } else { $el =& $factory->addElement('advcheckbox', $formFieldName, $widget['label']); if ($field['vocabulary']) { $yes = ''; $no = ''; if ($table->isYesNoValuelist($field['vocabulary'], $yes, $no)) { $el->setValues(array($no, $yes)); } } } return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { $table =& $record->_table; $widget =& $field['widget']; $factory = Dataface_FormTool::factory(); $attributes = array('class' => $widget['class'], 'id' => $field['name']); if ($field['repeat']) { $attributes['multiple'] = true; $attributes['size'] = 5; } $options = $record->_table->getValuelist($field['vocabulary']); //Dataface_FormTool::getVocabulary($record, $field); if (!isset($options)) { $options = array(); } $emptyOpt = array('' => df_translate('scripts.GLOBAL.FORMS.OPTION_PLEASE_SELECT', "Please Select...")); $opts = $emptyOpt; if ($record and $record->val($field['name'])) { if (!@$field['repeat'] and !isset($options[$record->strval($field['name'])])) { $opts[$record->strval($field['name'])] = $record->strval($field['name']); } else { if (@$field['repeat']) { $vals = $record->val($field['name']); if (is_array($vals)) { foreach ($vals as $thisval) { if (!isset($options[$thisval])) { $opts[$thisval] = $thisval; } } } } } } foreach ($options as $kopt => $opt) { $opts[$kopt] = $opt; } $el = $factory->addElement('select', $formFieldName, $widget['label'], $opts, $attributes); // Now to make it editable if (@$field['vocabulary']) { try { $rel =& Dataface_ValuelistTool::getInstance()->asRelationship($table, $field['vocabulary']); if ($rel and !PEAR::isError($rel)) { if (!is_a($rel, 'Dataface_Relationship')) { throw new Exception("The relationship object for the vocabulary " . $field['vocabulary'] . " could not be loaded."); } if (!$rel->getDomainTable()) { throw new Exception("The relationship object for the vocabulary " . $field['vocabulary'] . " could not be loaded or the domain table could not be found"); } $dtable = Dataface_Table::loadTable($rel->getDomainTable()); if ($dtable and !PEAR::isError($dtable)) { $perms = $dtable->getPermissions(); if (@$perms['new']) { $fields =& $rel->fields(); if (count($fields) > 1) { $valfield = $fields[1]; $keyfield = $fields[0]; } else { $valfield = $fields[0]; $keyfield = $fields[0]; } if (strpos($valfield, '.') !== false) { list($tmp, $valfield) = explode('.', $valfield); } if (strpos($keyfield, '.') !== false) { list($tmp, $keyfield) = explode('.', $keyfield); } $jt = Dataface_JavascriptTool::getInstance(); $jt->import('RecordDialog/RecordDialog.js'); //$suffix = '<script type="text/javascript" src="'.DATAFACE_URL.'/js/jquery-ui-1.7.2.custom.min.js"></script>'; //$suffix .= '<script type="text/javascript" src="'.DATAFACE_URL.'/js/RecordDialog/RecordDialog.js"></script>'; $suffix = '<a href="#" onclick="return false" id="' . df_escape($field['name']) . '-other">Other..</a>'; $suffix .= '<script> jQuery(document).ready(function($){ $("#' . $field['name'] . '-other").each(function(){ var tablename = "' . addslashes($dtable->tablename) . '"; var valfld = ' . json_encode($valfield) . '; var keyfld = ' . json_encode($keyfield) . '; var fieldname = ' . json_encode($field['name']) . '; var btn = this; $(this).RecordDialog({ table: tablename, callback: function(data){ var key = data[keyfld]; var val = data[valfld]; var $option = $(\'<option value="\'+key+\'">\'+val+\'</option>\'); $("#"+fieldname).append($option); $("#"+fieldname).val(key); if ( !val || val === key ){ var q = { "-action" : "field_vocab_value", "-key" : key, "-table" : ' . json_encode($field['tablename']) . ', "-field" : ' . json_encode($field['name']) . ' }; $.get(DATAFACE_SITE_HREF, q, function(res){ if ( res && res.code === 200 ){ $option.text(res.value); } }); } } }); }); }); </script> '; $widget['suffix'] = $suffix; } } } } catch (Exception $ex) { error_log($ex->getMessage()); } } //$el->setFieldDef($field); //return $el; return $el; }
function &buildWidget(&$record, &$field, &$form, $formFieldName, $new = false) { /* * * This field uses a table widget. * */ //$field['display'] = 'block'; $table =& $record->_table; $formTool =& Dataface_FormTool::getInstance(); $factory =& Dataface_FormTool::factory(); $widget =& $field['widget']; $el =& $factory->addElement('grid', $formFieldName, $widget['label']); $el->setProperties($widget); $rperms = $record->getPermissions(array('relationship' => $field['relationship'])); if (!$record->checkPermission('add new related record', array('relationship' => $field['relationship']))) { //echo "No add new ".$record->_table->tablename; $el->addNew = false; } if (!$record->checkPermission('add existing related record', array('relationship' => $field['relationship']))) { //echo "No add new ".$record->_table->tablename; $el->addExisting = false; } if (isset($field['relationship'])) { $relationship =& $table->getRelationship($field['relationship']); if (!$record->checkPermission('remove related record', array('relationship' => $field['relationship']))) { $el->delete = false; } else { if ($relationship->isOneToMany() and isset($rperms['delete related record']) and !@$rperms['delete related record']) { $el->delete = false; } } if (!$relationship->supportsRemove()) { $el->delete = false; } if (!$relationship->supportsAddNew()) { $el->addNew = false; } if (!$relationship->supportsAddExisting()) { $el->addExisting = false; } else { $el->addExistingFilters = $relationship->getAddExistingFilters(); } $el->table = $relationship->getDomainTable(); if (isset($widget['columns'])) { $columns = array_map('trim', explode(',', $widget['columns'])); } else { $columns = $relationship->_schema['short_columns']; } $count = 0; $subfactory = new HTML_QuickForm(); $dummyRelatedRecord = new Dataface_RelatedRecord($record, $relationship->getName()); //print_r($dummyRelatedRecord->getPermissions()); $orderCol = $relationship->getOrderColumn(); if (!$orderCol or PEAR::isError($orderCol)) { $el->reorder = false; } foreach ($columns as $column) { $colTable =& $relationship->getTable($column); if (!$colTable) { echo "Could not find table for column {$column}"; } $colPerms = $dummyRelatedRecord->getPermissions(array('field' => $column)); if (!@$colPerms['view']) { unset($colTable); unset($dummyRecord); continue; } // We need to be a bit more refined on this one. We need to take // into account the context being that we are in a relationship. $dummyRecord = new Dataface_Record($colTable->tablename, $record->vals()); /* if ( !$dummyRecord->checkPermission('view', array('field'=>$column, 'recordmask'=>array('view'=>1))) ) { unset($colTable); unset($dummyRecord); continue; } */ $colFieldDef =& $colTable->getField($column); $columnElement =& $formTool->buildWidget($dummyRecord, $colFieldDef, $subfactory, $column, false); $defaultValue = $colTable->getDefaultValue($column); $columnElement->setValue($defaultValue); $el->defaults[$column] = $defaultValue; $el->addField($colFieldDef, $columnElement, $colPerms); unset($columnElement); unset($colFieldDef); unset($dummyRecord); unset($colTable); unset($elementFilter); } } else { if (isset($widget['fields'])) { $widget_fields =& $widget['fields']; foreach ($widget_fields as $widget_field) { $widget_field =& Dataface_Table::getTableField($widget_field, $this->db); if (PEAR::isError($widget_field)) { return $widget_field; } $widget_widget = $formTool->buildWidget($record, $widget_field, $factory, $widget_field['name']); $defaultValue = $table->getDefaultValue($widget_field['name']); $widget_widget->setValue($defaultValue); $el->addField($widget_widget); $el->defaults[$widget_field['name']] = $defaultValue; } } else { if (isset($field['fields'])) { foreach (array_keys($field['fields']) as $field_key) { $widget_widget = $formTool->buildWidget($record, $field['fields'][$field_key], $factory, $field['fields'][$field_key]['name']); $defaultValue = $table->getDefaultValue($widget_field['name']); $widget_widget->setValue($defaultValue); $el->defaults[$widget_field['name']] = $defaultValue; $el->addField($widget_widget); unset($widget_widget); } } } } return $el; }