diff --git a/code/DevTasks.php b/code/DevTasks.php index ed6a2c7..383b637 100644 --- a/code/DevTasks.php +++ b/code/DevTasks.php @@ -6,17 +6,27 @@ * @package DevTasks * */ -class DevTasks extends LeftAndMainExtension { - public function init() { +class DevTasks extends LeftAndMainExtension implements PermissionProvider +{ + + public function init() + { + parent::init(); + + if (!Permission::check("VIEW_DEVTASKS")) return; + $tasks = array( 'devbuild' => array( 'title' => 'Dev/Build', 'link' => 'dev/build', - 'reset_time' => '5000' + 'reset_time' => '5000', + 'error_handler' => 'newtab', + 'success_handler' => 'ignore' ) ); $config_tasks = Config::inst()->get(__CLASS__, 'tasks'); + if (is_array($config_tasks)) { $tasks = array_merge($tasks, $config_tasks); } @@ -26,14 +36,28 @@ public function init() { $attributes = array( 'class' => 'devbuild-trigger', 'data-title' => (isset($values['title']) ? $values['title'] : $item), - 'data-link' => $values['link'], - 'data-reset-time' => (isset($values['reset_time']) ? $values['reset_time'] : '5000') + 'data-link' => (isset($values['link']) ? $values['link'] : 'dev/build'), + 'data-reset-time' => (isset($values['reset_time']) ? $values['reset_time'] : '5000'), + 'data-error-handler' => (isset($values['error_handler']) ? $values['error_handler'] : 'newtab'), + 'data-success-handler' => (isset($values['success_handler']) ? $values['success_handler'] : 'ignore') ); // priority controls the ordering of the link in the stack. The // lower the number, the lower in the list $priority = -90; + CMSMenu::add_link($item, '', '#', $priority, $attributes); + } } + + public function providePermissions() + { + return array( + "VIEW_DEVTASKS" => "Access dev task menu", + ); + } + } + +?> diff --git a/javascript/LeftAndMain.Fancy-devbuild.js b/javascript/LeftAndMain.Fancy-devbuild.js index 3900ac6..c1cec3a 100644 --- a/javascript/LeftAndMain.Fancy-devbuild.js +++ b/javascript/LeftAndMain.Fancy-devbuild.js @@ -1,7 +1,50 @@ (function($) { var dev_trigger = ".devbuild-trigger", + all_states = "error loading success"; default_doc_title = document.title; + $.fn.set_trigger = function(message, current_class) { + document.title = message; + $(this) + .removeClass(all_states) + .data("executing", true) + .addClass(current_class) + .children(".text") + .text(message); + }; + + $.fn.reset_trigger = function() { + document.title = default_doc_title; + $(this).attr('href', '#') + .removeClass(all_states) + .removeData("executing") + .children(".text") + .text($(this).data('title')); + }; + + function completion_handler(data, handler_option){ + if (handler_option){ + switch (handler_option) { + //case 'log': + // break; + // case 'popup': + // dialog.ssdialog({iframeUrl: this.attr('href'), autoOpen: true, dialogExtraClass: extraClass}); + // break; + case 'newtab': + // Display error in new tab/window + with(window.open('about:blank').document) { + open(); + write(data); + close(); + } + break; + case 'ignore': + default: + break; + } + } + } + // look out for click $(dev_trigger).each(function(){ $(this).children('.text').text($(this).data('title')); @@ -23,13 +66,15 @@ // search for any errors from returned data if (data.search("ERROR") > 0) { + completion_handler(data, $this.data('error-handler')); // change text to show an error has occured $this.attr('href', $this.data('link')) - .set_trigger("Build failed","error"); + .set_trigger("Build failed", "error"); setTimeout(function(){ $this.reset_trigger(); }, reset_time); } else { + completion_handler(data, $this.data('success-handler')); // change text back to default changes = $(data).find("li[style='color: blue'], li[style='color: green']").length; $this.set_trigger(changes+" Changes occurred","success"); @@ -42,28 +87,12 @@ }) .fail(function( xhr, textStatus, errorThrown ) { $this.set_trigger("Request failed: "+errorThrown,"error"); + setTimeout(function(){ + $this.reset_trigger(); + }, reset_time); }); return false; }); - $.fn.set_trigger = function(message, current_class) { - document.title = message; - $(this) - .removeClass("error loading success") - .data("executing", true) - .addClass(current_class) - .children(".text") - .text(message); - }; - - $.fn.reset_trigger = function() { - document.title = default_doc_title; - $(this).attr('href', '#') - .removeClass("error loading success") - .removeData("executing") - .children(".text") - .text($(this).data('title')); - }; - }(jQuery));