Example #1
0
 /**
  * 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;
 }
Example #2
0
 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;
 }
Example #3
0
 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;
 }
Example #4
0
    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;
    }