示例#1
0
    public function editJSONEditForm($currentConfigKey)
    {
        $json = json_encode(Config::get($currentConfigKey));
        $js = <<<JS
            var json = {$json};
            main.load(json);
            main.resize();
            var pageDirty = false;
            \$().ready(function() {
                window.onbeforeunload = function () {
                    if ( ! pageDirty ) return;
                    return 'Changes have been made on this page and will be discarded.'
                };
                \$('textarea.jsonformatter-textarea').change( function() {
                    pageDirty = true;
                });
                \$('div.jsoneditor-value').change( function() {
                    pageDirty = true;
                });
                \$('#fldCfgValue').val( editor.get() );
            });

            function submitClicked () {
                var button = \$('#editJSONEditFormButton').attr('disabled',true);

                var orig = \$('#fldCfgValue').val();
                var ed   = editor.get();    // JSON Editor, RHS fields labels
                var form = formatter.get(); // Formatted Text Editor LHS

                if ( orig == ed && orig == form ) {
                    pageDirty = false;
                    alert( 'No changes, nothing to save' );
                    button.attr('disabled',false );
                    return false;
                }
                else if ( orig != ed && orig == form ) {
                    if ( confirm( 'Looks like you have made changes in the JSON Editor on right pane and not copied to Formatted Text Editor on left pane. Ok to save changes?' ) ) {
                        pageDirty = false;
                        \$('#fldCfgValue').val( ed );
                        \$('#editJSONEditForm').submit();
                        return true;
                    }
                    else {
                        button.attr('disabled',false );
                        return false;
                    }
                }
                else if ( orig == ed && orig != form ) {
                    if ( confirm( 'Looks like you have made changes in the Formatted Text Editor on left pane and not copied to the JSON Editor on right pane. Ok to save?' ) ) {
                        pageDirty = false;
                        \$('#fldCfgValue').val( form );
                        \$('#editJSONEditForm').submit();
                        return true;
                    }
                    else {
                        button.attr('disabled',false );
                        return false;
                    }
                }
                else if ( orig != ed && orig != form ) {
                    if ( ed == form ) {
                        pageDirty = false;
                        \$('#fldCfgValue').val( ed );
                        \$('#editJSONEditForm').submit();
                        return true;
                    }
                    else {
                        alert( 'You have changed both the JSON Editor on right pane and the Formatted Text Editor on left pane and they are inconsistent. ' +
                               'Please press one of the arrow buttons to fix and re-submit' );
                        button.attr('disabled',false );
                        return false;
                    }
                }
            }

            \$('body')
                .on( 'focus', '[contenteditable]', function() {
                    var t = \$(this);
                    t.data('before', t.html());
                    return t;
                })
                .on( 'blur keyup paste input', '[contenteditable]', function() {
                    var t = \$(this);
                    if (t.data('before') !== t.html() ) {
                        t.data('before', t.html());
                        t.trigger('change');
                    }
                    return t;
                });
JS;
        return JS::library(JS::JQUERY) . JS::library('jsoneditor.css') . JS::library('interface.css') . JS::library('jsoneditor.js') . JS::library('interface.js') . Tag::div(['id' => 'auto']) . Tag::div(['id' => 'contents', 'height' => '100%']) . Tag::table(['border' => '0', 'height' => '100%', 'width' => '100%']) . Tag::tr() . Tag::td(['valign' => 'top', 'width' => '45%', 'height' => '100%']) . Tag::hTag('b') . '&nbsp;&nbsp;&nbsp;&nbsp;Formatted Text Editor' . Tag::_hTag('b') . Tag::div(['id' => 'jsonformatter']) . Tag::_div() . Tag::_td() . Tag::td(['valign' => 'top', 'width' => '10%', 'align' => 'center']) . Tag::div(['id' => 'splitter']) . Tag::_div() . Tag::_td() . Tag::td(['valign' => 'top', 'width' => '45%', 'height' => '100%']) . Tag::hTag('b') . '&nbsp;&nbsp;&nbsp;&nbsp;JSON Editor' . Tag::_hTag('b') . Tag::div(['id' => 'jsoneditor']) . Tag::_div() . Tag::_td() . Tag::_tr() . Tag::_table() . Tag::_div() . Tag::_div() . Tag::form(['id' => 'editJSONEditForm'], false) . MenuUtils::responseObject()->set('fldCfgKey', $currentConfigKey)->action(__CLASS__ . '->saveConfig()')->toHidden() . Tag::textArea('fldCfgValue', '', ['id' => 'fldCfgValue', 'style' => 'display: none;']) . '<b>Currently editing : <i>' . $currentConfigKey . '</i></b> ' . Tag::button('Save', ['onClick' => 'submitClicked();', 'id' => 'editJSONEditFormButton']) . Tag::_form() . JS::javaScript($js);
    }
示例#2
0
 protected function askCommand()
 {
     $text = Request::get('CMDTEXT');
     $html = '<b>Direct Command Access</b><br/>' . Tag::form() . Response::factory()->action(__CLASS__ . '->runCommand()')->toHidden() . Tag::textArea('CMDTEXT', $text, ['rows' => 5, 'cols' => 40]) . '<br/>' . Tag::submit('Go') . Tag::_form();
     return $html;
 }