Esempio n. 1
0
 /**
  * Returns a link that'll trigger a JavaScript function using the onclick
  * handler.
  *
  * Examples:
  *   JsHelper::button_to_function("Greeting", "alert('Hello world!')");
  *
  * @param type <description>
  * @param type <description>
  * @param type <description>
  *
  * @return type <description>
  */
 function button_to_function($name, $function, $html_options = array())
 {
     $html_options['type'] = 'button';
     $html_options['value'] = $name;
     $html_options['onclick'] = sprintf('%s%s;', isset($html_options['onclick']) ? $html_options['onclick'] . '; ' : '', $function);
     return TagHelper::tag('input', $html_options);
 }
Esempio n. 2
0
 function test_TagHelper()
 {
     $this->assertEqual(TagHelper::tag('br'), '<br />');
     $this->assertEqual(TagHelper::tag('input', array('type' => 'text', 'value' => 'Insert your text >> "HERE"')), '<input type="text" value="Insert your text &gt;&gt; &quot;HERE&quot;" />');
     $this->assertEqual(TagHelper::tag('hr', array('style' => '', 1234 => 'This is not possible')), '<hr />');
     $this->assertEqual(TagHelper::content_tag('p', 'Have a look "HERE"'), '<p>Have a look "HERE"</p>');
     $this->assertEqual(TagHelper::content_tag('textarea', 'Have a look "HERE"', array('name' => 'details')), '<textarea name="details">Have a look "HERE"</textarea>');
     $this->assertEqual(TagHelper::cdata_section('Have a look "HERE"'), '<![CDATA[Have a look "HERE"]]>');
 }
Esempio n. 3
0
 public function permission_check_box(&$Permission, &$Extenssion, &$Role)
 {
     $options = array('id' => 'permissions_' . $Permission->getId() . '_' . $Role->getId(), 'name' => 'permissions[' . $Permission->getId() . '][' . $Role->getId() . ']', 'type' => 'checkbox');
     $Role->permission->load();
     if (in_array($Permission->getId(), $Permission->collect($Role->permissions, 'id', 'id'))) {
         $options['checked'] = 'checked';
     }
     if (!$Role->get('is_enabled')) {
         $options['disabled'] = 'disabled';
     }
     return TagHelper::tag('input', array('name' => $options['name'], 'type' => 'hidden', 'value' => 0)) . TagHelper::tag('input', $options);
 }
Esempio n. 4
0
function error_messages_for($class)
{
    if (empty($class->errors)) {
        return;
    }
    $errors = $class->errors;
    $out = array(TagHelper::tag('ul', array('class' => 'errors')));
    foreach ($errors as $col => $error) {
        array_push($out, TagHelper::content_tag('li', TagHelper::content_tag('p', $error)));
    }
    array_push($out, TagHelper::close_tag('ul'));
    $message = TagHelper::content_tag('h2', "Errors occured saving this record", array('class' => 'error_message'));
    return TagHelper::content_tag('div', $message . join("\n", $out), array('class' => 'error_container'));
}
Esempio n. 5
0
 public static function feed_link_tag($url, $type = 'rss', $options = array())
 {
     $options = array_merge(array('title' => strtoupper($type)), $options);
     unset($options['href'], $options['rel'], $options['type']);
     return TagHelper::tag('link', array_merge(array('rel' => 'alternate', 'href' => $url, 'type' => self::$feed_types[$type]), $options));
 }
Esempio n. 6
0
 /**
  * Displays an image which when clicked will submit the form.
  *
  * <tt>source</tt> is passed to AssetTagHelper#image_path
  */
 function image_submit_tag($source, $options = array())
 {
     return TagHelper::tag('input', array_merge(array('type' => 'image', 'src' => $this->_controller->asset_tag_helper->image_path($source)), $options));
 }
Esempio n. 7
0
 /**
  * Generates a form containing a sole button that submits to the
  * URL given by _options_.  Use this method instead of +link_to+
  * for actions that do not have the safe HTTP GET semantics
  * implied by using a hypertext link.
  *
  * The parameters are the same as for +link_to+.  Any _html_options_
  * that you pass will be applied to the inner +input+ element.
  * In particular, pass
  * 
  *   'disabled' => true/false
  *
  * as part of _html_options_ to control whether the button is
  * disabled.  The generated form element is given the class
  * 'button-to', to which you can attach CSS styles for display
  * purposes.
  *
  * Example 1:
  *
  *   // inside of controller for "feeds"
  *   $url->button_to('Edit', array('action' => 'edit', 'id' => 3));
  *
  * Generates the following HTML (sans formatting):
  *
  *   <form method="post" action="/feeds/edit/3" class="button-to">
  *     <div><input type="submit" value="Edit"  /></div>
  *   </form>
  *
  * Example 2:
  *
  *   $url->button_to('Destroy', array('action' => 'destroy', 'id' => 3 , 'confirm' => 'Are you sure?'));
  *
  * Generates the following HTML (sans formatting):
  *
  *   <form method="post" action="/feeds/destroy/3" class="button-to">
  *     <div><input onclick="return confirm('Are you sure?');" value="Destroy" type="submit" /></div>
  *   </form>
  *
  * Note: This method generates HTML code that represents a form.
  * Forms are "block" content, which means that you should not try to
  * insert them into your HTML where only inline content is expected.
  * For example, you can legally insert a form inside of a <div> or
  * <td> element or in between <p> elements, but not in the middle of
  * a run of text, nor can you place a form within another form.
  * (Bottom line: Always validate your HTML before going public.)
  */
 function button_to($name, $options = array(), $html_options = array())
 {
     $html_options = $this->_convert_boolean_attributes($html_options, 'disabled');
     if (!empty($html_options['confirm'])) {
         $html_options['onclick'] = 'return ' . $this->_confirm_javascript_function($html_options['confirm']) . ';';
         unset($html_options['confirm']);
     }
     $url = is_string($options) ? $options : $this->url_for($options);
     $name = !empty($name) ? $name : (is_string($options) ? $options : htmlentities($this->url_for($options)));
     $html_options = array_merge($html_options, array('type' => 'submit', 'value' => $name));
     return '<form method="post" action="' . $url . '" class="button-to"><div>' . TagHelper::tag('input', $html_options) . '</div></form>';
 }
Esempio n. 8
0
 function to_check_box_tag($options = array(), $checked_value = '1', $unchecked_value = '0')
 {
     $options['type'] = 'checkbox';
     $options['value'] = $checked_value;
     $value = $this->getValue();
     if (is_numeric($value)) {
         $checked = $value != 0;
     } elseif (is_string($value)) {
         $checked = $value == $checked_value;
     } else {
         $checked = !empty($value);
     }
     if ($checked || isset($options['checked']) && $options['checked'] == 'checked') {
         $options['checked'] = 'checked';
     } else {
         unset($options['checked']);
     }
     $this->add_default_name_and_id($options);
     return TagHelper::tag('input', array('name' => $options['name'], 'type' => 'hidden', 'value' => $unchecked_value)) . TagHelper::tag('input', $options);
 }
Esempio n. 9
0
 /**
  * Returns a button input tag that will submit form using XMLHttpRequest in
  * the background instead of regular reloading POST arrangement. The '$opt'
  * argument is the same as in 'form_remote_tag()'.
  *
  * @param type <description>
  * @param type <description>
  * @param type <description>
  *
  * @return type <description>
  */
 function submit_to_remote($name, $value, $options = array())
 {
     if (!isset($options['with'])) {
         $options['with'] = 'Form.serialize(this.form)';
     }
     if (!isset($options['html'])) {
         $options['html'] = array();
     }
     $options['html']['type'] = 'button';
     $options['html']['onclick'] = PrototypeHelper::remote_function($options) . '; return false;';
     $options['html']['name'] = $name;
     $options['html']['value'] = $value;
     return TagHelper::tag('input', $options['html']);
 }
Esempio n. 10
0
 function test_tag()
 {
     $foo = TagHelper::tag('img', array('src' => 'test.gif'));
     $this->assertEqual('<img src="test.gif" />', $foo);
 }
Esempio n. 11
0
    /**
    * Returns a link that'll trigger a JavaScript +function+ using the 
    * onclick handler.
    *
    * Examples:
    *   $javascript_helper->button_to_function("Greeting", "alert('Hello world!')");
    *   $javascript_helper->button_to_function("Delete", "if confirm('Really?'){ do_delete(); }"));
    */
    function button_to_function($name, $function, $html_options = array())
    {
        $default_html_options = array(
        'type'  => 'button',
        'value' => $name,
        'onclick' => (!empty($html_options['onclick']) ?  "{$html_options['onclick']}; " : ""). "{$function};"
        );

        $html_options = array_merge($default_html_options, $html_options);

        return TagHelper::tag('input', $html_options);
    }
Esempio n. 12
0
 /**
  * Output an HTML text field
  *
  * @param string $name Name of field
  * @param string $value Initial value to display in field
  * @param array $html_attributes Set of HTML attributes and other options
  * return string Text field HTML
  */
 public static function text_field_tag($name, $value = null, $html_attributes = array())
 {
     return TagHelper::tag('input', array_merge(array('type' => 'text', 'name' => $name, 'value' => $value, 'id' => self::sanitize_id($name)), $html_attributes));
 }
Esempio n. 13
0
 /**
  * Returns an image tag converting the +options+ into html options on the tag, but with these special cases:
  *
  * * <tt>alt</tt>  - If no alt text is given, the file name part of the +src+ is used (capitalized and without the extension)
  * * <tt>size</tt> - Supplied as "XxY", so "30x45" becomes width="30" and height="45"
  *
  * The +src+ can be supplied as a...
  * * full path, like "/my_images/image.gif"
  * * file name, like "rss.gif", that gets expanded to "/images/rss.gif"
  * * file name without extension, like "logo", that gets expanded to "/images/logo.png"
  */
 function image_tag($source, $options = array())
 {
     if (!empty($options['size'])) {
         list($options['width'], $options['height']) = split('x|X| ', trim(str_replace(' ', '', $options['size'])));
         unset($options['size']);
     }
     $options['src'] = $this->image_path($source);
     $options['alt'] = !empty($options['alt']) ? $options['alt'] : AkInflector::titleize(substr(basename($options['src']), 0, strpos(basename($options['src']), '.')), 'first');
     return TagHelper::tag('img', $options);
 }
Esempio n. 14
0
 public function __toString()
 {
     if (strtolower($this->config['method']) == 'put' || strtolower($this->config['method']) == 'delete') {
         $method = 'POST';
         $extra = FormTagHelper::hidden_field('_method', '_method', $this->config['method']);
     } else {
         $method = $this->config['method'];
     }
     $form_options = array_merge(array('name' => strtolower($this->get_form_name()), 'method' => $method, 'action' => $this->config['path']), $this->tag_options);
     if (isset($this->config['type'])) {
         $form_options['enctype'] = $this->config['type'];
     }
     $return = TagHelper::tag('form', $form_options);
     if (isset($extra)) {
         $return = $return . $extra;
     }
     return $return;
 }