Beispiel #1
0
 public function build()
 {
     $output = "";
     unset($this->attributes['type'], $this->attributes['size']);
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = $this->description;
             }
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             $output = Form::select($this->name, $this->options, $this->value, $this->attributes) . $this->extra_output;
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = $output;
 }
 public function build()
 {
     $output = "";
     if (!isset($this->style)) {
         $this->style = "margin:0 2px 0 0; vertical-align: middle";
     }
     unset($this->attributes['id']);
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = $this->description;
             }
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             $this->attributes['multiple'] = 'multiple';
             $this->attributes['data-placeholder'] = $this->attributes['placeholder'];
             $this->attributes['placeholder'] = null;
             $output .= Form::select($this->name . '[]', $this->options, $this->values, $this->attributes);
             $output .= $this->extra_output;
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = $output;
 }
Beispiel #3
0
 public function build()
 {
     $output = "";
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if ($this->type == 'hidden' || $this->value == "") {
                 $output = "";
             } elseif (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = nl2br(htmlspecialchars($this->value));
             }
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             Rapyd::js('tinymce/tinymce.min.js');
             Rapyd::js('tinymce/tinymce_editor.js');
             $output = Form::textarea($this->name, $this->value, $this->attributes);
             Rapyd::script("function elFinderBrowser (field_name, url, type, win) {" . "tinymce.activeEditor.windowManager.open({" . "file: '" . route('elfinder.tinymce4') . "'," . "title: 'elFinder 2.0'," . "width: 900," . "height: 450," . "resizable: 'yes'" . "}, {" . "setUrl: function (url) {" . "win.document.getElementById(field_name).value = url;" . "}" . "});" . "return false;" . "}");
             Rapyd::script("tinymce.init({selector: '#" . $this->name . "', file_browser_callback : elFinderBrowser, plugins: 'image', convert_urls: false});");
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = "\n" . $output . "\n" . $this->extra_output . "\n";
 }
Beispiel #4
0
 public function build()
 {
     $output = "";
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = $this->checked ? $this->checked_output : $this->unchecked_output;
             }
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             //dd($this->checked);
             $output = Form::checkbox($this->name, $this->checked_value, $this->checked, $this->attributes) . $this->extra_output;
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = $output;
 }
Beispiel #5
0
 public function build()
 {
     $output = "";
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if ($this->type == 'hidden' || $this->value == "") {
                 $output = "";
             } elseif (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = nl2br(htmlspecialchars($this->value));
             }
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             $output = Form::text($this->name, $this->value, $this->attributes);
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = "\n" . $output . "\n" . $this->extra_output . "\n";
 }
 public function build()
 {
     $output = "";
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = $this->description;
             }
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             foreach ($this->options as $val => $label) {
                 $this->checked = (!is_null($this->value) and $this->value == $val);
                 $output .= Form::radio($this->name, $val, $this->checked) . ' ' . $label . $this->separator;
             }
             $output .= $this->extra_output;
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = $output;
 }
Beispiel #7
0
 public function build()
 {
     $output = "";
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if ($this->type == 'hidden' || $this->value == "") {
                 $output = "";
             } elseif (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = nl2br(htmlspecialchars($this->value));
             }
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             Rapyd::js('redactor/jquery.browser.min.js');
             Rapyd::js('redactor/redactor.min.js');
             Rapyd::css('redactor/css/redactor.css');
             $output = Form::textarea($this->name, $this->value, $this->attributes);
             Rapyd::script("\$('#" . $this->name . "').redactor();");
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = "\n" . $output . "\n" . $this->extra_output . "\n";
 }
 public function build()
 {
     $output = "";
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "show":
             $output = $this->value;
             $output = "<div class='help-block' style='background-color:" . $output . "'>&nbsp;</div>";
             break;
         case "create":
         case "modify":
             Rapyd::css('colorpicker/css/bootstrap-colorpicker.min.css');
             Rapyd::js('colorpicker/js/bootstrap-colorpicker.min.js');
             $output = Form::text($this->name, $this->value, $this->attributes);
             $output .= Rapyd::script("\n                        \$('#" . $this->name . "').colorpicker({\n                            format: 'hex'\n                        });");
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = $output;
 }
Beispiel #9
0
 public function build()
 {
     $output = "";
     unset($this->attributes['type']);
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "show":
             if (!isset($this->value)) {
                 $value = $this->layout['null_label'];
             } else {
                 $value = str_replace($this->serialization_sep, ' ', $this->value);
             }
             $output = $value;
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             Rapyd::css('datepicker/datepicker3.css');
             Rapyd::js('datepicker/bootstrap-datepicker.js');
             if ($this->language != "en") {
                 Rapyd::js('datepicker/locales/bootstrap-datepicker.' . $this->language . '.js');
             }
             unset($this->attributes['id']);
             //$this->attributes['class'] = "form-control";
             $from = Form::text($this->name . '[from]', @$this->values[0], $this->attributes);
             $to = Form::text($this->name . '[to]', @$this->values[1], $this->attributes);
             $output = '
                         <div id="range_' . $this->name . '_container">
                             <div class="input-daterange">
                                <div class="input-group">
                                    <div class="input-group-addon">&ge;</div>
                                    ' . $from . '
                                </div>
                                <div class="input-group">
                                     <div class="input-group-addon">&le;</div>
                                     ' . $to . '
                                </div>
                             </div>
                         </div>';
             Rapyd::pop_script();
             Rapyd::script("\n                        \$('#range_{$this->name}_container .input-daterange').datepicker({\n                            format: '{$this->formatToDate()}',\n                            language: '{$this->language}',\n                            todayBtn: 'linked',\n                            autoclose: true\n                        });");
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = $output;
 }
Beispiel #10
0
 public function build($view = '')
 {
     $this->initJsWidget();
     $view == '' and $view = 'rapyd::datatree';
     $this->open = Form::open($this->attributes);
     $this->close = Form::hidden('save', 1) . Form::close();
     // we save on POST and only if the widget's own input variable is filled
     // because sometimes we have more than a tree widget on the same page
     // but just one save
     if (\Request::method() == 'POST' && \Input::get($this->name)) {
         $this->lockAndSave();
     }
     $this->data = $this->source->find($this->source->getKey())->getDescendants()->toHierarchy();
     Persistence::save();
     $this->rows = $this->makeRowsRecursive($this->data);
     return \View::make($view, array('dg' => $this, 'buttons' => $this->button_container, 'label' => $this->label));
 }
Beispiel #11
0
 public function build()
 {
     $output = "";
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             break;
         case "create":
         case "modify":
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = "\n" . $output . "\n" . $this->extra_output . "\n";
 }
Beispiel #12
0
 public function build()
 {
     $output = "";
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if ($this->type == 'hidden' || $this->value == "") {
                 $output = "";
             } elseif (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = $this->value;
             }
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             $lower = Form::number($this->name . '[]', @$this->values[0], $this->attributes);
             $upper = Form::number($this->name . '[]', @$this->values[1], $this->attributes);
             $output = '
                         <div id="range_' . $this->name . '_container">
                                <div class="input-group">
                                    <div class="input-group-addon">&ge;</div>
                                    ' . $lower . '
                                </div>
                                <div class="input-group">
                                     <div class="input-group-addon">&le;</div>
                                     ' . $upper . '
                                </div>
                         </div>';
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = "\n" . $output . "\n" . $this->extra_output . "\n";
 }
 public function build()
 {
     $output = "";
     if (!isset($this->style)) {
         $this->style = "margin:0 2px 0 0; vertical-align: middle";
     }
     unset($this->attributes['id']);
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = $this->description;
             }
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             //dd($this->options, $this->values);
             foreach ($this->options as $val => $label) {
                 $this->checked = in_array($val, $this->values);
                 //echo ((int)$this->checked)."<br />";
                 $output .= sprintf($this->format, Form::checkbox($this->name . '[]', $val, $this->checked) . $label) . $this->separator;
             }
             $output .= $this->extra_output;
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = $output;
 }
Beispiel #14
0
 public function prepareForm()
 {
     $form_attr = array('url' => $this->process_url, 'class' => "form-horizontal", 'role' => "form", 'method' => $this->method);
     $form_attr = array_merge($form_attr, $this->attributes);
     // See if we need a multipart form
     foreach ($this->fields as $field_obj) {
         if (in_array($field_obj->type, array('file', 'image'))) {
             $form_attr['files'] = 'true';
             break;
         }
     }
     // Set the form open and close
     if ($this->status == 'show') {
         $this->open = '<div class="form">';
         $this->close = '</div>';
     } else {
         $this->open = Form::open($form_attr);
         $this->close = Form::hidden('save', 1) . Form::close();
         if ($this->method == "GET") {
             $this->close = Form::hidden('search', 1) . Form::close();
         }
     }
     if (isset($this->validator)) {
         $this->errors = $this->validator->messages();
         $this->error .= implode('<br />', $this->errors->all());
     }
 }
Beispiel #15
0
    public function build()
    {
        $output = "";
        Rapyd::css('autocomplete/autocomplete.css');
        Rapyd::js('autocomplete/typeahead.bundle.min.js');
        Rapyd::js('template/handlebars.js');
        unset($this->attributes['type']);
        if (parent::build() === false) {
            return;
        }
        switch ($this->status) {
            case "disabled":
            case "show":
                if (!isset($this->value)) {
                    $output = $this->layout['null_label'];
                } elseif ($this->value == "") {
                    $output = "";
                } else {
                    if ($this->relation != null) {
                        $name = $this->rel_field;
                        $value = @$this->relation->get()->first()->{$name};
                    } else {
                        $value = $this->value;
                    }
                    $output = nl2br(htmlspecialchars($value));
                }
                $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
                break;
            case "create":
            case "modify":
                if (Input::get("auto_" . $this->name)) {
                    $autocomplete = Input::get("auto_" . $this->name);
                } elseif ($this->relation != null) {
                    $name = $this->rel_field;
                    $autocomplete = @$this->relation->get()->first()->{$name};
                } elseif (count($this->local_options)) {
                    $autocomplete = $this->description;
                } else {
                    $autocomplete = $this->value;
                }
                $output = Form::text("auto_" . $this->name, $autocomplete, array_merge($this->attributes, array('id' => "auto_" . $this->name))) . "\n";
                $output .= Form::hidden($this->name, $this->value, array('id' => $this->name));
                $output = '<span id="th_' . $this->name . '">' . $output . '</span>';
                if ($this->remote) {
                    $script = <<<acp

                    var blod_{$this->name} = new Bloodhound({
                        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('auto_{$this->name}'),
                        queryTokenizer: Bloodhound.tokenizers.whitespace,
                        remote: {
                            url: '{$this->remote}?q=%QUERY',
                            ajax: {
                                complete: function(response){
                                    response.responseJSON.forEach(function (item) {
                                        blod_{$this->name}.valueCache[item.{$this->record_label}] = item.{$this->record_id};
                                    });
                                }
                            }
                        }
                    });
                    blod_{$this->name}.valueCache = {};
                    blod_{$this->name}.initialize();

                    \$('#th_{$this->name} .typeahead').typeahead({
                        highlight: true,
                        minLength: {$this->min_chars},
                    }, {
                        displayKey: '{$this->record_label}',
                        name: '{$this->name}',
                        source: blod_{$this->name}.ttAdapter(),
                        templates: {
                            suggestion: Handlebars.compile('{{{$this->record_label}}}')
                        }
                    }).on("typeahead:selected typeahead:autocompleted",
                        function (e,data) {
                            \$('#{$this->name}').val(data.{$this->record_id});
                    }).on("typeahead:closed,typeahead:change",
                        function (e,data) {
                            if ('{$this->must_match}') {
                                var _label = \$.trim(\$(this).val());
                                if ( !(_label in blod_{$this->name}.valueCache) ) {
                                    \$('#{$this->name}').val('');
                                    \$(this).val('');
                                } else {
                                    //Fill data to hidden input, when direct copy data to input without choose from auto-complete results.
                                    \$('#{$this->name}').val(blod_{$this->name}.valueCache[_label]);
                                }
                            } else {
                                if (\$(this).val() == '') {
                                    \$('#{$this->name}').val('');
                                }
                            }
                    });
                    \$('#th_{$this->name} .typeahead').keypress(function (e) {
                        if (e.which == 13) {
                            e.preventDefault();
                        }
                    });
                    
                    
acp;
                    Rapyd::script($script);
                } elseif (count($this->options)) {
                    $options = json_encode($this->local_options);
                    //options
                    $script = <<<acp

                    var {$this->name}_options = {$options};
                    var blod_{$this->name} = new Bloodhound({
                        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
                        queryTokenizer: Bloodhound.tokenizers.whitespace,
                        local: {$this->name}_options
                    });


                    blod_{$this->name}.initialize();

                    \$('#th_{$this->name} .typeahead').typeahead({
                         hint: true,
                         highlight: true,
                         minLength: {$this->min_chars}
                    },
                    {
                        name: '{$this->name}',
                        displayKey: 'value',
                        source: blod_{$this->name}.ttAdapter()
                    }).on("typeahead:selected typeahead:autocompleted",
                        function (e,data) {
                            \$('#{$this->name}').val(data.key);
                    }).on("typeahead:closed",
                        function (e,data) {
                            if (\$(this).val() == '') {
                                \$('#{$this->name}').val('');
                            }
                    });
acp;
                    Rapyd::script($script);
                }
                break;
            case "hidden":
                $output = Form::hidden($this->db_name, $this->value);
                break;
            default:
        }
        $this->output = "\n" . $output . "\n" . $this->extra_output . "\n";
    }
Beispiel #16
0
 public function build()
 {
     $output = "";
     unset($this->attributes['type']);
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "show":
             if (!isset($this->value)) {
                 $value = $this->layout['null_label'];
             } else {
                 $value = $this->isodatetimeToHuman($this->value);
             }
             $output = $value;
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             if ($this->value != "") {
                 if (!$this->is_refill) {
                     $this->value = $this->isodatetimeToHuman($this->value);
                 }
             }
             Rapyd::css('datetimepicker/datetimepicker3.css');
             Rapyd::js('datetimepicker/bootstrap-datetimepicker.js');
             if ($this->language != "en") {
                 Rapyd::js('datetimepicker/locales/bootstrap-datetimepicker.' . $this->language . '.js');
             }
             $output = Form::text($this->name, $this->value, $this->attributes);
             Rapyd::script("\n                        \$('#" . $this->name . "').datetimepicker({\n                            format: '{$this->formatTodatetime()}',\n                            language: '{$this->language}',\n                            todayBtn: 'linked',\n                            autoclose: true\n                        });");
             break;
         case "hidden":
             $output = Form::hidden($this->db_name, $this->value);
             break;
         default:
     }
     $this->output = $output;
 }
Beispiel #17
0
 public function build()
 {
     $this->path = $this->parseString($this->path);
     $this->web_path = $this->parseString($this->web_path);
     $output = "";
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if ($this->type == 'hidden' || $this->value == "") {
                 $output = "";
             } elseif (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = nl2br(htmlspecialchars($this->value));
             }
             $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
             break;
         case "create":
         case "modify":
             if ($this->old_value) {
                 $output .= '<div class="clearfix">';
                 $output .= link_to($this->web_path . $this->value, $this->value) . "&nbsp;";
                 $output .= Form::checkbox($this->name . '_remove', 1, (bool) Input::get($this->name . '_remove')) . " " . trans('rapyd::rapyd.delete') . " <br/>\n";
                 $output .= '</div>';
             }
             $output .= Form::file($this->name, $this->attributes);
             break;
         case "hidden":
             $output = Form::hidden($this->name, $this->value);
             break;
         default:
     }
     $this->output = "\n" . $output . "\n" . $this->extra_output . "\n";
 }
Beispiel #18
0
    /**
     * Render for group field.
     *
     * @return string
     */
    public function render()
    {
        $htmlRepeaterTemplate = '';
        $tdFirstBody = "<td class='field-order'>\n                                <label class='circle' >%s</label>\n                                <input type='hidden' name='%s' id='%s' value='%s'/>\n                            </td>";
        $repeaterDeleteId = 'repeater_delete_' . $this->locale . '_' . $this->getFieldId();
        $repeaterTableId = 'repeater_table_' . $this->locale . '_' . $this->getFieldId();
        $repeaterDeleteName = sprintf('%s[fields][%s][delete]', $this->locale, $this->getFieldId());
        $tdDeleteBtn = "<td class='last'>\n\t\t\t\t\t\t\t<a class='btn-delete' onclick=\"deleteRepeaterField('{$this->locale}_{$this->getFieldId()}',this)\">\n\t\t\t\t\t\t\t\t<span class='glyphicon glyphicon-minus'></span>\n\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t</td>";
        $groups = $this->groupFields;
        $headers = $this->repeaterHeaders;
        $columns = count($headers) + 2;
        $tableHeader = "<tr class='repeater-group'>\n\t\t\t\t\t\t\t<th colspan='{$columns}'>" . $this->getLabel() . '</th>
						</tr>';
        $columnWidth = 50;
        if (count($headers)) {
            $columnWidth = 100 / ($columns - 2);
            // make header
            $tdHeader = '';
            $tdTemplate = '';
            foreach ($headers as $field) {
                $tdHeader .= sprintf("<th class='caption' width='%s'>%s</th>", $columnWidth . '%', $field->getLabel());
                $field->setLabel('');
                $tdTemplate .= sprintf("<td width='%s'>%s</td>", $columnWidth . '%', $field->render());
            }
            $groupName = $this->locale . '[fields][%s][order][%s]';
            $groupName = sprintf($groupName, $this->fieldId, 'clone');
            // assign template to create new item of repeater
            $tdFirstNew = sprintf($tdFirstBody, -1, $groupName, $groupName, -1);
            $tdTemplate = $tdFirstNew . $tdTemplate . $tdDeleteBtn;
            $repeaterFormat = "<tr class='repeater-template' id='repeater_template_%s_%s'>%s</tr>";
            $htmlRepeaterTemplate = sprintf($repeaterFormat, $this->locale, $this->getFieldId(), $tdTemplate);
            // assign header lable for repeater
            $tdHeader = '<th>&nbsp;</th>' . $tdHeader . "<th class='last'>&nbsp;</th>";
            $tableHeader .= $tdHeader;
        }
        $trBody = '';
        if (count($groups)) {
            // make row
            $i = 1;
            foreach ($groups as $groupId => $group) {
                $groupName = $this->locale . '[fields][%s][order][%s]';
                $groupOrder = $group['order'];
                $groupName = sprintf($groupName, $this->fieldId, $groupId);
                $fields = $group['fields'];
                $tdBody = '';
                foreach ($fields as $field) {
                    $field->setLabel('');
                    $tdBody .= sprintf("<td width='%s'>%s</td>", $columnWidth . '%', $field->render());
                }
                $tdFirstNew = sprintf($tdFirstBody, $i, $groupName, $groupName, $groupOrder);
                $tdBody = $tdFirstNew . $tdBody . $tdDeleteBtn;
                $trBody .= sprintf("<tr data-id='%s' class='another-field'>%s</tr>", $groupId, $tdBody);
                ++$i;
            }
        }
        $tableBody = $trBody . $htmlRepeaterTemplate;
        $htmlAddNewBtn = "<a  class ='btn btn-primary btn-flat' onclick=\"addRepeaterField('{$this->locale}_{$this->getFieldId()}')\">" . trans('Add Item') . '</a>';
        $tableFooter = sprintf("<td colspan='{$columns}'>%s</td>", $htmlAddNewBtn);
        $tableHtml = "<table  class='table-repeater ' id='{$repeaterTableId}' >\n\t\t\t\t\t\t\t<thead>%s</thead>\n\t\t\t\t\t\t\t<tbody class='sortable'>%s</tbody>\n\t\t\t\t\t\t\t<tfoot>%s</tfoot>\n\t\t\t\t\t\t  </table>";
        $html = sprintf($tableHtml, $tableHeader, $tableBody, $tableFooter);
        // assign index for repeater to make new item
        $repeaterIndexId = 'repeater_index_' . $this->locale . '_' . $this->getFieldId();
        $inputIndex = FormFacade::hidden($repeaterIndexId, 0, array('id' => $repeaterIndexId));
        $inputDelete = FormFacade::hidden($repeaterDeleteName, '', array('id' => $repeaterDeleteId));
        $html .= $inputIndex . $inputDelete;
        $html .= sprintf("<script>\$( document ).ready(function() {bindSortableForRepeater('%s');});</script>", $repeaterTableId);
        return $html;
    }
Beispiel #19
0
Form::macro('radioSwitch', function ($name, $values = null, $checked = null, $options = array()) {
    if (is_null($values)) {
        $values = [1 => transpine('helpers.yes'), 0 => transpine('helpers.no')];
        $checked = is_null($checked) ? null : (int) $checked;
    }
    if (is_null($checked)) {
        $checked = array_keys($values)[0];
    }
    $html = '<p class="field switch">';
    foreach ($values as $value => $label) {
        $options['id'] = $name . $value . microtime();
        $html .= Form::radio($name, $value, $checked === $value, $options);
        $labelClass = $value == 0 ? 'cb-disable' : 'cb-enable';
        $labelClass .= $checked === $value ? ' selected' : '';
        $html .= Form::label($options['id'], $label, ['class' => $labelClass]);
    }
    $html .= '</p>';
    return $html;
});
/**
 * Create a checkbox input field with forced zero value for unchecked.
 *
 * @param  string  $name
 * @param  mixed   $value
 * @param  bool    $checked
 * @param  array   $options
 * @return string
 */
Form::macro('checkboxForced', function ($name, $value = 1, $checked = null, $options = array()) {
    return Form::hidden($name, 0) . Form::checkbox($name, $value, $checked, $options);
});
Beispiel #20
0
 public function build()
 {
     $output = "";
     $this->attributes["class"] = "form-control";
     if (parent::build() === false) {
         return;
     }
     switch ($this->status) {
         case "disabled":
         case "show":
             if ($this->type == 'hidden' || $this->value == "") {
                 $output = "";
             } elseif (!isset($this->value)) {
                 $output = $this->layout['null_label'];
             } else {
                 $output = "<img border=\"0\" src=\"//maps.googleapis.com/maps/api/staticmap?center={$this->value['lat']},{$this->value['lon']}&zoom={$this->zoom}&size=500x500\">";
             }
             $output = "<div class='help-block'>" . $output . "</div>";
             break;
         case "create":
         case "modify":
             $output = Form::hidden($this->lat, $this->value['lat'], ['id' => $this->lat]);
             $output .= Form::hidden($this->lon, $this->value['lon'], ['id' => $this->lon]);
             $output .= '<div id="map_' . $this->name . '" style="width:500px; height:500px"></div>';
             $output .= '<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script>';
             \Rapyd::script("\n        \n            function initialize()\n            {\n                var latitude = document.getElementById('{$this->lat}');\n                var longitude = document.getElementById('{$this->lon}');\n                var zoom = {$this->zoom};\n        \n                var LatLng = new google.maps.LatLng(latitude.value, longitude.value);\n        \n\n                var mapOptions = {\n                    zoom: zoom,\n                    center: LatLng,\n                    panControl: false,\n                    zoomControl: true,\n                    scaleControl: true,\n                    mapTypeId: google.maps.MapTypeId.ROADMAP\n                }\n        \n                var map = new google.maps.Map(document.getElementById('map_{$this->name}'),mapOptions);\n\n                var marker = new google.maps.Marker({\n                    position: LatLng,\n                    map: map,\n                    title: 'Drag Me!',\n                    draggable: true\n                });\n\n                var update_hidden_fields = function () {\n                    latitude.value = marker.getPosition().lat();\n                    longitude.value = marker.getPosition().lng();\n                }\n                google.maps.event.addListener(marker, 'dragend', update_hidden_fields);\n\n                \$(document.getElementById('map_{$this->name}')).data('map', map);\n                \$(document.getElementById('map_{$this->name}')).data('marker', marker);\n                \$(document.getElementById('map_{$this->name}')).data('update_hidden_fields', update_hidden_fields);\n            }\n            initialize();\n        ");
             break;
         case "hidden":
             $output = '';
             //Form::hidden($this->db_name, $this->value);
             break;
         default:
     }
     $this->output = "\n" . $output . "\n" . $this->extra_output . "\n";
 }
Beispiel #21
0
    public function build()
    {
        $output = "";
        //typeahead
        Rapyd::css('autocomplete/autocomplete.css');
        Rapyd::js('autocomplete/typeahead.bundle.min.js');
        Rapyd::js('template/handlebars.js');
        //tagsinput
        Rapyd::css('autocomplete/bootstrap-tagsinput.css');
        Rapyd::js('autocomplete/bootstrap-tagsinput.min.js');
        unset($this->attributes['type']);
        if (parent::build() === false) {
            return;
        }
        switch ($this->status) {
            case "disabled":
            case "show":
                if (!isset($this->value)) {
                    $output = $this->layout['null_label'];
                } else {
                    $output = $this->description;
                }
                $output = "<div class='help-block'>" . $output . "&nbsp;</div>";
                break;
            case "create":
            case "modify":
                $output = Form::text($this->name, '', array_merge($this->attributes, array('id' => "" . $this->name))) . "\n";
                if ($this->remote) {
                    $script = <<<acp

                    \$('#{$this->name}').tagsinput({
                      itemValue: '{$this->record_id}',
                      itemText: '{$this->record_label}'
                    });
                    {$this->fill_tags}

                    var blod_{$this->name} = new Bloodhound({
                        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('{$this->name}'),
                        queryTokenizer: Bloodhound.tokenizers.whitespace,
                        remote: '{$this->remote}?q=%QUERY'
                    });
                    blod_{$this->name}.initialize();

                    \$('#{$this->name}').tagsinput('input').typeahead(null, {
                        name: '{$this->name}',
                        displayKey: '{$this->record_label}',
                        highlight: true,
                        minLength: {$this->min_chars},
                        source: blod_{$this->name}.ttAdapter()
                    }).bind('typeahead:selected', \$.proxy(function (obj, data) {
                        this.tagsinput('add', data);
                        this.tagsinput('input').typeahead('val', '');
                    }, \$('#{$this->name}')));


acp;
                    Rapyd::script($script);
                } elseif (count($this->options)) {
                    $options = json_encode($this->local_options);
                    //options
                    $script = <<<acp

                    var {$this->name}_options = {$options};


                    \$('#{$this->name}').tagsinput({
                      itemValue: 'key',
                      itemText: 'value'
                    });
                    {$this->fill_tags}


                    var blod_{$this->name} = new Bloodhound({
                        datumTokenizer: Bloodhound.tokenizers.obj.whitespace('value'),
                        queryTokenizer: Bloodhound.tokenizers.whitespace,
                        local: {$this->name}_options
                    });


                    blod_{$this->name}.initialize();
                    \$('#{$this->name}').tagsinput('input').typeahead({
                         hint: true,
                         highlight: true,
                         minLength: {$this->min_chars}
                    },
                    {
                        name: '{$this->name}',
                        displayKey: 'value',
                        source: blod_{$this->name}.ttAdapter()
                    }).bind('typeahead:selected', \$.proxy(function (obj, data) {
                        this.tagsinput('add', data);
                        this.tagsinput('input').typeahead('val', '');
                    }, \$('#{$this->name}')));

acp;
                    Rapyd::script($script);
                }
                break;
            case "hidden":
                $output = Form::hidden($this->db_name, $this->value);
                break;
            default:
        }
        $this->output = "\n" . $output . "\n" . $this->extra_output . "\n";
    }