Ejemplo n.º 1
0
    function test_observe_form()
    {
        $foo = PrototypeHelper::observe_form('form_id', array('url' => 'http://update', 'frequency' => 0, 'update' => 'update_id'));
        $exp = <<<EXPECTED
<script type="text/javascript">
//<![CDATA[
new Form.EventObserver("form_id", 0, function(element, value) {new Ajax.Updater('update_id', 'http://update', {asynchronous:true, evalScripts:false, parameters:value})});
//]]>
</script>
EXPECTED;
        $this->assertEqual($exp, $foo);
    }
Ejemplo n.º 2
0
 /**
  * @ignore
  */
 function get_ajax_options()
 {
     static $ajax_options;
     if (!$ajax_options) {
         $ajax_options = array('before', 'after', 'condition', 'url', 'asynchronous', 'method', 'insertion', 'position', 'form', 'with', 'update', 'script') + PrototypeHelper::get_callbacks();
     }
     return $ajax_options;
 }
Ejemplo n.º 3
0
<li id="item_<?php 
echo $item->id;
?>
">
  <input type="checkbox" name="item[<?php 
echo $item->id;
?>
][done]"
          <?php 
echo $item->done ? 'checked="checked"' : '';
?>
          onClick="<?php 
echo PrototypeHelper::remote_function(array('url' => $controller->url_for('todo/toggle/' . $item->id)));
?>
" />
  <?php 
echo $item->description;
?>
  <a href="<?php 
echo $controller->url_for('todo/edit/' . $item->id);
?>
">edit</a>
  <a href="<?php 
echo $controller->url_for('todo/delete/' . $item->id);
?>
">delete</a>
</li>
Ejemplo n.º 4
0
 /**
  * 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)));
 }
Ejemplo n.º 5
0
 /**
  * Makes the element with the DOM ID specified by +element_id+ receive
  * dropped draggable elements (created by draggable_element).
  * and make an AJAX call  By default, the action called gets the DOM ID 
  * of the element as parameter.
  *
  * Example:
  *   <%= drop_receiving_element("my_cart", :url => 
  *     { :controller => "cart", :action => "add" }) %>
  *
  * You can change the behaviour with various options, see
  * http://script.aculo.us for more documentation.
  */
 function drop_receiving_element($element_id, $options = array())
 {
     $options['with'] = !empty($options['with']) ? $options['with'] : "'id='" . urlencode(element . id);
     $options['onDrop'] = !empty($options['onDrop']) ? $options['onDrop'] : "function(element){" . PrototypeHelper::remote_function($options) . "}";
     foreach ($options as $key => $option) {
         /**
          * @todo: fix this code when implemented PrototypeHelper
          * 
          * if (in_array(PrototypeHelper::AJAX_OPTIONS[$option])) {
          *      unset($options[$option]);
          * }
          */
     }
     if (in_array($options['accept'])) {
         $options['accept'] = JavascriptHelper::_array_or_string_for_javascript($options['accept']);
     }
     if (in_array($options['hoverclass'])) {
         $options['hoverclass'] = "'{$options['hoverclass']}'";
     }
     return JavascriptHelper::javascript_tag("Droppables.add('{$element_id}', " . JavascriptHelper::_options_for_javascript($options) . ")");
 }