/** Creates a Dual Select windows * @param string $lName Left Column name * @param array $lList Left Column name * @param string $rName Right Column name * @param array $rList Right Column name * @param int $ht Height * @returns String The Html pf a dual select */ public static function dualSelect($lName, $lList, $rName, $rList, $ht = 8) { $title = array("title" => "Select items is the left list to move to the selected list. " . "Move items in the right list to remove from the selected list. " . "Select buttons in the moddle to move all the items in the list"); $msg = ""; $msg .= Tag::table($title); $msg .= Tag::tr(); $msg .= Tag::td("align=center"); $msg .= "Out of List<br>"; $msg .= Lists::select($lName, $lList, "onChange=\"selMove ( '{$lName}','{$rName}',false );\" Size={$ht} Multiple"); $msg .= Tag::_td(); $msg .= Tag::td("valign=middle"); $msg .= "<br>" . Tag::button(">>", "onClick=\"selMove ( '{$lName}','{$rName}',true );\""); $msg .= "<br>" . Tag::button("<<", "onClick=\"selMove ( '{$rName}','{$lName}',true );\""); $msg .= Tag::_td(); $msg .= Tag::td("align=center"); $msg .= "In the List<br>"; $msg .= Lists::select($rName, $rList, "onChange=\"selMove ( '{$rName}','{$lName}',false );\" Size={$ht} Multiple"); $msg .= Tag::hidden($rName . "Result"); $msg .= Tag::_td(); $msg .= Tag::_tr(); $msg .= Tag::_table(); return $msg; }
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') . ' 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') . ' 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); }
/** * @return string */ public function toHtml() { $this->auditStartRow(); $rowsPerPage = intval($this->getPageSize()); $startingRow = intval($this->getStart()); $startingPage = intval($this->get(self::STARTING_PAGE)); $totalRows = intval($this->getRows()); $saveStartingRow = intval($this->getStart()); if ($rowsPerPage <= 0) { $rowsPerPage = self::$pagination[self::ROWS_PER_PAGE]; } // Not enough rows for pagination if ($totalRows <= $rowsPerPage) { if ($this->dispPageSize && $totalRows > 10) { return Tag::div($this->attribs) . Tag::form(['method' => 'get']) . $this->toHidden([self::ROWS_PER_PAGE]) . ' Max Rows: ' . Lists::select($this->toFormName(self::ROWS_PER_PAGE), self::$itemsPerPageList, ['default' => $rowsPerPage, 'onChange' => 'submit();']) . Tag::_form() . Tag::_div(); } else { return ''; } } if ($startingPage > 0) { $startingRow = ($startingPage - 1) * $rowsPerPage; $this->set(self::STARTING_PAGE, 0); } if ($startingRow >= $totalRows) { $startingRow = $totalRows - 1; } $pageContainingStartRow = intval($startingRow / $rowsPerPage); $this->set(self::SQL_START, $rowsPerPage * $pageContainingStartRow); // Get number of pages $numberOfPages = intval($totalRows / $rowsPerPage); if ($totalRows % $rowsPerPage != 0) { $numberOfPages++; } $previousPage = ''; $nextPage = ''; $firstPage = ''; $lastPage = ''; $pageSizeHtml = ''; $html = [[], []]; // This is the navigation from the current page forward for ($currentPage = $pageContainingStartRow + 1, $incr = 1; $currentPage < $numberOfPages - 1; $currentPage += $incr) { $startingRowForThisPage = $currentPage * $rowsPerPage; $currentPageDisplay = $currentPage + 1; $this->set(self::STARTING_ROW, $startingRowForThisPage); $html[1][] = Tag::hRef($this->toUrl(), number_format($currentPageDisplay), ['title' => 'Go to Page ' . $currentPageDisplay, 'class' => $this->styles[self::PAGE_LINK_CLASS]]); $incr *= count($html[1]); } // This is the navigation for next and last page if ($pageContainingStartRow + 1 < $numberOfPages) { $this->setStart($rowsPerPage * ($numberOfPages - 1)); $lastPage = Tag::button('>> ' . number_format($numberOfPages), ['onclick' => "location.href='" . $this->toUrl() . "';return true;", 'title' => 'Go to Last Page - ' . $numberOfPages, 'class' => $this->styles[self::PAGE_BUTTON_CLASS]]); $this->setStart($rowsPerPage * ($pageContainingStartRow + 1)); $nextPage = Tag::button('>', ['onclick' => "location.href='" . $this->toUrl() . "';return true;", 'title' => 'Go to Next Page - ' . ($pageContainingStartRow + 2), 'class' => $this->styles[self::PAGE_BUTTON_CLASS]]); } // Navigation for the current page nackwards for ($currentPage = $pageContainingStartRow - 1, $incr = 1; $currentPage > 0; $currentPage -= $incr) { $startingRowForThisPage = $currentPage * $rowsPerPage; $currentPageDisplay = $currentPage + 1; $this->setStart($startingRowForThisPage); $html[0][] = Tag::hRef($this->toUrl(), number_format($currentPageDisplay), ['title' => 'Go to Page ' . $currentPageDisplay, 'class' => $this->styles[self::PAGE_LINK_CLASS]]); $incr *= count($html[0]); } // Reverse the array so that it appears in correct order for pagination $html[0] = array_reverse($html[0]); // Navigation for previous and first pages if ($pageContainingStartRow != 0) { // Calculate navigation for first page $this->setStart(0); $firstPage = Tag::button('<< 1', ['onclick' => "location.href='" . $this->toUrl() . "';return true;", 'title' => 'Go to First Page - 1', 'class' => $this->styles[self::PAGE_BUTTON_CLASS]]); // Calculate navigation for previous page $this->setStart($rowsPerPage * ($pageContainingStartRow - 1)); $previousPage = Tag::button('< ', ['onclick' => "location.href='" . $this->toUrl() . "';return true;", 'title' => 'Go to Previous Page - ' . ($pageContainingStartRow - 1), 'class' => $this->styles[self::PAGE_BUTTON_CLASS]]); } $this->setStart($saveStartingRow); $curPage = (string) ($pageContainingStartRow + 1); $exemptVars = [self::STARTING_PAGE]; // Create the drop down to set the number of rows displayed per page if ($this->dispPageSize) { $exemptVars[] = self::ROWS_PER_PAGE; $pageSizeHtml = ' Rows: ' . Lists::select($this->toFormName(self::ROWS_PER_PAGE), self::$itemsPerPageList, ['default' => $rowsPerPage, 'title' => 'This changes the number of rows to display', 'onChange' => 'submit();']); } return Tag::div($this->attribs) . Tag::form(['method' => 'get']) . $this->toHidden($exemptVars) . $firstPage . $previousPage . ' ' . join(' · ', $html[0]) . ' ' . Tag::text($this->toFormName(self::STARTING_PAGE), ['value' => $curPage, 'align' => 'middle', 'size' => 1 + max(1, strlen($curPage) - 1), 'title' => 'Manually enter the page number that you want and press enter', 'style' => 'font-weight:bold;']) . ' ' . join(' · ', $html[1]) . ' ' . $nextPage . $lastPage . $pageSizeHtml . Tag::_form() . Tag::_div(); }