Left base folder: C:\Documents and Settings\Olga\My Documents\Downloads\webform-6.x-3.0-beta5(2)\webform Right base folder: C:\xampp\htdocs\ogorun\sites\all\modules\webform --- includes\webform.components.inc 2010-06-02 00:54:12.000000000 +-0300 +++ includes\webform.components.inc 2010-06-02 00:53:26.000000000 +-0300 @@ -420,72 +420,74 @@ '#description' => t('Optional. In the menu, the heavier items will sink and the lighter items will be positioned nearer the top.'), '#weight' => 4, ); // Add conditional fields. $conditional_components = array(); - $counter = 0; $last_pagebreak_slice = 0; foreach ($node->webform['components'] as $cid => $test_component) { // Only components before the pagebreak can be considered. - if ($test_component['type'] == 'pagebreak') { - $last_pagebreak_slice = $counter; - } - if (isset($component['cid']) && $cid == $component['cid']) { + if (isset($component['cid']) && $cid == $component['cid']) { break; } if (webform_component_feature($test_component['type'], 'conditional')) { - $conditional_components[$cid] = $test_component; + $conditional_components[$test_component['form_key']] = $test_component['name']; } - $counter++; } - if ($component['type'] != 'pagebreak') { - $fieldset_description = t('Create a rule to control whether or not to skip this page.'); - } - else { - $fieldset_description = t('Create a rule to control whether or not to show this form element.'); - } - $conditional_components = array_slice($conditional_components, 0, $last_pagebreak_slice, TRUE); $form['conditional'] = array( '#weight' => 10, '#type' => 'fieldset', '#title' => t('Conditional rules'), '#collapsible' => TRUE, - '#collapsed' => TRUE, + '#collapsed' => !$component['extra']['condition'], '#description' => t('Create a rule to control whether or not to show this form element.'), '#tree' => FALSE, ); $form['conditional']['extra'] = array( '#tree' => TRUE, ); - $form['conditional']['extra']['conditional_component'] = array( - '#type' => 'select', - '#title' => t('Component'), - '#options' => webform_component_list($node, $conditional_components, FALSE, TRUE), - '#description' => t('Select another component to decide whether to show or hide this component. You can only select components occurring before the most recent pagebreak.'), - '#default_value' => $component['extra']['conditional_component'], + + $form['conditional']['extra']['condition'] = array( + '#type' => 'hidden', + '#default_value' => $component['extra']['condition'] ); - $form['conditional']['extra']['conditional_operator'] = array( - '#type' => 'select', - '#title' => t('Operator'), - '#options' => array( - '=' => t('Is one of'), - '!=' => t('Is not one of') - ), - '#description' => t('Determines whether the list below is inclusive or exclusive.'), - '#default_value' => $component['extra']['conditional_operator'], + + $form['conditional']['extra']['conditional_mandatory'] = array( + '#type' => 'checkbox', + '#title' => t('Conditional mandatory'), + '#default_value' => $component['extra']['conditional_mandatory'] ); - $form['conditional']['extra']['conditional_values'] = array( - '#type' => 'textarea', - '#title' => t('Values'), - '#description' => t('List values, one per line, that will trigger this action. If you leave this blank, this component will always display.'), - '#default_value' => $component['extra']['conditional_values'], + + $form['conditional']['extra']['constructor'] = array( + '#type' => 'markup', + '#value' => '
' ); if (empty($conditional_components)) { $form['conditional']['#access'] = FALSE; + } + else { + $settings = array( + 'webformConditionalSettings' => array( + 'currentConditions' => $component['extra']['condition'] ? json_decode($component['extra']['condition']) : new StdClass(), + 'lOperandFormElement' => 'select', + 'availableLOperands' => $conditional_components, + 'buttonFlags' => array( + 'addElement' => true, + 'addAndGroup' => true, + 'addOrGroup' => true, + 'showExpression' => true + ), + ) + ); + drupal_add_js($settings, 'setting'); + $path = drupal_get_path('module','webform'); + drupal_add_js($path . '/js/webform_conditional.js'); + drupal_add_js($path . '/le/jquery.json-2.2.min.js'); + drupal_add_js($path . '/le/le.conditionsConstructor.js'); + drupal_add_css($path . '/le/conditions_constructor.css'); } // Add the fields specific to this component type: $additional_form_elements = (array) webform_component_invoke($component['type'], 'edit', $component); if (empty($additional_form_elements)) { drupal_set_message(t('The webform component of type @type does not have an edit function defined.', array('@type' => $component['type']))); --- +++ js\webform_conditional.js 2010-05-29 17:23:20.000000000 +-0300 @@ -0,0 +1,97 @@ +Drupal.behaviors.webformCond = function(context) { + if (typeof Drupal.settings['webformConditional'] != 'undefined' && Drupal.settings['webformConditional']['objects']) { + var options = { + mandatoryFieldSelector: '#edit-webform-conditional-mandatory', + objectByName: function(name) { + return $('[name*="['+name+']"]'); + }, + feldsetByName: function(name) { + return $('#webform-component-' + name); + }, + getWrapper: function(name,info) { + if(info['type']=='fieldset' || info['type']=='markup'){ + return $('#webform-component-' + name); + } + var cssName = name.replace(/_/g,"-"); + if(info['fieldsetId']!=''){ + cssName = info['fieldsetId'].replace(/_/g,"-") + "-" + cssName; + } + + if (info['type'] == 'grid') { + return $('[name*=\"['+name+']\"]').parent('.form-item').parents('.form-item'); + } + var cssId = "#edit-submitted-" + cssName + "-wrapper"; + if($(cssId).length==0) { + cssId = "#edit-submitted-" + cssName + "-1-wrapper"; + return $(cssId).parent().parent(); + } else { + return $(cssId); + } + }, + expression: $.le.defaultOptions.conditionalForm.expression + }; + + + options.setMandatoryLikeView = function(name, info) { + var wrap = options.getWrapper(name, info).parent(); + if (!wrap.find('label span.form-required').length) { + $('*').appendTo(wrap.find('label')); + } + }; + + options.expression.operandHandler.left = function (val) { + var obj = options.objectByName(val); + if (obj.length) { + if(obj.filter('input:checked').length == 1) { + return obj.filter('input:checked').val(); + } else if(obj.filter('input:checkbox,input:radio').length) { + return false; + } else if(obj.filter('option:selected').length == 1) { + return obj.filter('option:selected').val(); + } else { + return obj.val(); + } + } + else if (Drupal.settings.webformConditional.previousPagesFields[val]) { + return Drupal.settings.webformConditional.previousPagesFields[val]; + } + else { + return false; + } + + }; + + $.extend(options, Drupal.settings.webformConditional); + + $('form.webform-client-form').leConditionalForm(options); + } +}; + +Drupal.behaviors.webformCondSettings = function(context) { + + $('#webform-conditions-constructor:not(.webformCondSettings-processed)', context) + .addClass('webformCondSettings-processed') + .each(function() { + var domObj = this; + var $this = $(this); + var options = Drupal.settings.webformConditionalSettings; + options.defaultNewElement = function () { + var el; + for (el in options.availableLOperands) { + break; + } + return { + optype: 'el', + left: el, + op: 'opEqual', + right: '', + neg: false + }; + } + var conditions = $this.leConstructor(Drupal.settings.webformConditionalSettings.currentConditions, options); + + $('#webform-component-edit-form').submit(function () { + $('#edit-extra-condition').val(domObj.le.expression.getSerialised()); + }); + }); +}; --- +++ le\icons\condition.png 2009-08-04 14:01:32.000000000 +-0300 @@ -0,0 +1,6 @@ +‰PNG + +