Skip to content

Commit

Permalink
Merge pull request #16 from gorriecoe/new-config-options
Browse files Browse the repository at this point in the history
Cool, nice job. I'l look at building in some more options for error handling. 

I'd like to have it popup in a dialog.
  • Loading branch information
mediabeastnz committed Jan 28, 2016
2 parents e1bd322 + e4116c8 commit ce02707
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 23 deletions.
10 changes: 7 additions & 3 deletions code/DevTasks.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ public function init()
'devbuild' => array(
'title' => 'Dev/Build',
'link' => 'dev/build',
'reset_time' => '5000'
'reset_time' => '5000',
'error_handler' => 'newtab',
'success_handler' => 'ignore'
)
);

Expand All @@ -34,8 +36,10 @@ 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
Expand Down
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 ce02707

Please sign in to comment.