Skip to content

Commit

Permalink
Merge remote-tracking branch 'mediabeastnz/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gorriecoe committed Feb 1, 2016
2 parents e46a589 + ce02707 commit f503f3a
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 25 deletions.
34 changes: 29 additions & 5 deletions code/DevTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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",
);
}

}

?>
69 changes: 49 additions & 20 deletions javascript/LeftAndMain.Fancy-devbuild.js
Original file line number Diff line number Diff line change
@@ -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'));
Expand All @@ -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");
Expand All @@ -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));

0 comments on commit f503f3a

Please sign in to comment.