/** * @ignore */ function options_for_ajax($options) { $js_opt = PrototypeHelper::build_callbacks($options); $js_opt['asynchronous'] = isset($options['type']) ? $options['type'] != 'synchronous' : 'true'; if (isset($options['method'])) { $js_opt['method'] = PrototypeHelper::method_option_to_s($options['method']); } if (isset($options['position'])) { $js_opt['insertion'] = 'Insertion.' . TextHelper::camelize($options['position']); } $js_opt['evalScripts'] = !isset($options['script']) || $options['script'] == '0' || $options['script'] == 'false' ? 'false' : 'true'; if (isset($options['form'])) { $js_opt['parameters'] = 'Form.serialize(this)'; } else { if (isset($options['submit'])) { $js_opt['parameters'] = "Form.serialize(document.getElementById('{$options['submit']}'))"; } else { if (isset($options['with'])) { $js_opt['parameters'] = $options['with']; } } } return JsHelper::options_for_javascript($js_opt); }
/** * Makes the elements with the DOM ID specified by '$element_id' sortable * by drag-and-drop and make an AJAX call whenever the sort order has * changed. By default, the action called gets the serialized sortable * element as parameters. * * Example: * <php echo sortable_element($my_list, array( * 'url' => '@order', * )) ?> * * In the example, the action gets a '$my_list' array parameter * containing the values of the ids of elements the sortable consists * of, in the current order. * * You can change the behaviour with various options, see * http://script.aculo.us for more documentation. */ function sortable_element($element_id, $options = array()) { if (!isset($options['with'])) { $options['with'] = "Sortable.serialize('{$element_id}')"; } if (!isset($options['onUpdate'])) { $options['onUpdate'] = sprintf('function(){%s}', PrototypeHelper::remote_function($options)); } foreach (PrototypeHelper::get_ajax_options() as $key) { unset($options[$key]); } foreach (array('tag', 'overlap', 'constraint', 'handle') as $option) { if (isset($options[$option])) { $options[$option] = "'{$options[$option]}'"; } } if (isset($options['containment'])) { $options['containment'] = self::array_or_string_for_javascript($options['containment']); } if (isset($options['hoverclass'])) { $options['hoverclass'] = "'{$options['hoverclass']}'"; } if (isset($options['only'])) { $options['only'] = self::array_or_string_for_javascript($options['only']); } return JsHelper::javascript_tag(sprintf("Sortable.create('%s', %s)", $element_id, JsHelper::options_for_javascript($options))); }