public static function display($menuClasses = null) { $id = 'MenuUtils_display' . Invocation::next(); $jsLibraries = JS::libraryWithDependancies(JS::JQUERY_UI); $activeMenu = Request::get(self::ACTIVE_MENU, 0); $js = <<<JS \$().ready ( function () { \$( '#{$id}' ).show() .accordion({ collapsible: true, active: {$activeMenu} }); }); JS; $html = ''; $html .= Tag::div(['id' => $id, 'style' => 'font-size: 0.8em; width:250px; text-align:left; display:none;']); foreach (self::getMenuItems($menuClasses) as $header => $menuList) { $html .= Tag::hTag('h3') . Tag::hRef('#', $header) . Tag::_hTag('h3') . Tag::div() . Tag::ul(); foreach ($menuList as $row) { $html .= Tag::li(); if (isset($row['slug'])) { $html .= Tag::hRef(Cfg::siteUrl() . '/menu.php?S=' . $row['slug'], $row['name'], $row['attribs']); } else { $html .= Tag::hRef($row['url'], $row['name'], $row['attribs']); } $html .= Tag::_li(); } $html .= Tag::_ul() . Tag::_div(); } $html .= Tag::_div(); return $jsLibraries . JS::javaScript($js) . $html; }
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(); }
public static function reload($callBack, $url, $numOfSeconds = 20, $css = 'ReloadWidget') { $id = '_' . Invocation::next(); $js = <<<JS var countDownInterval{$id} = {$numOfSeconds}; //configure refresh interval (in seconds) var countDownTime{$id} = countDownInterval{$id} + 1; var reloadTimes{$id} = 0; var counter{$id}; function countDown{$id}(){ countDownTime{$id}--; \$('#stop{$id}').show(); \$('#start{$id}').hide(); if ( countDownTime{$id} <= 0 ) { clearTimeout(counter{$id}); updateReloadArea{$id}(); return; } \$('#countDownText{$id}').html( countDownTime{$id} + '' ); counter{$id} = setTimeout( "countDown{$id}()", 1000 ); } function stopCount{$id}(){ clearTimeout(counter{$id}) \$('#stop{$id}').hide(); \$('#start{$id}').show(); } function updateReloadArea{$id}(){ countDownTime{$id} = countDownInterval{$id} + 1; reloadTimes{$id} = reloadTimes{$id} + 1; \$('#reload{$id}').load('{$url}&R='+reloadTimes{$id}, function() { countDown{$id} (); }); } \$().ready ( function () { countDown{$id} (); }); JS; $html = 'Next ' . Tag::hRef("javascript:countDownTime{$id}=0", 'refresh', ['title' => 'Click here to refresh now.', 'class' => $css]) . ' in ' . Tag::hTag('span', ['id' => "countDownText{$id}", 'class' => $css]) . $numOfSeconds . Tag::_hTag('span') . ' seconds ' . Tag::hRef("javascript:stopCount{$id}()", 'Stop', ['id' => "stop{$id}", 'title' => 'Click here to stop the timer.', 'class' => $css]) . Tag::hRef("javascript:countDown{$id}()", 'Start', ['id' => "start{$id}", 'title' => 'Click here to start the timer.', 'class' => $css]) . '<br/>' . Tag::div(['id' => "reload{$id}", 'class' => $css]) . call_user_func($callBack) . Tag::_div(); return JS::library(JS::JQUERY) . JS::javaScript($js) . $html; }