summaryrefslogtreecommitdiff
path: root/public/javascripts/toxcreate.js
diff options
context:
space:
mode:
authormr <mr@mrautenberg.de>2010-04-29 13:08:34 +0200
committermr <mr@mrautenberg.de>2010-04-29 13:08:34 +0200
commit66ed931ecf53aa167edabe8993ae45b759685294 (patch)
tree49251bb7bfd696af57a91c5e2e06030f2591b642 /public/javascripts/toxcreate.js
parent1773ca0998bfc0731826ecde5db9ceca7588f4fd (diff)
view modifications and jquery scripts delete, checkstatus, toggleWarnings
Diffstat (limited to 'public/javascripts/toxcreate.js')
-rwxr-xr-xpublic/javascripts/toxcreate.js112
1 files changed, 112 insertions, 0 deletions
diff --git a/public/javascripts/toxcreate.js b/public/javascripts/toxcreate.js
new file mode 100755
index 0000000..890f6d0
--- /dev/null
+++ b/public/javascripts/toxcreate.js
@@ -0,0 +1,112 @@
+$(function() {
+
+ jQuery.fn.toggleWarnings = function(id) {
+ var id = id;
+ this.bind("click", function() {
+ if($("a#show_model_" + id + "_warnings").html()=="show") {
+ $("dd#model_" + id + "_warnings").slideDown("slow");
+ $("a#show_model_" + id + "_warnings").html("hide");
+ }else{
+ $("dd#model_" + id + "_warnings").slideUp("slow");
+ $("a#show_model_" + id + "_warnings").html("show");
+ }
+ });
+ return false;
+ };
+
+ checkStati = function(stati) {
+ stati = stati.split(", ")
+ $("body")
+ var newstati = new Array;
+ $.each(stati, function(){
+ if(checkStatus(this) > 0) newstati.push(this);
+ });
+ if (newstati.length > 0) var statusCheck = setTimeout('checkStati("' + newstati.join(", ") + '")',10000);
+ };
+
+ checkStatus = function(id) {
+ if(id == "") return -1;
+ var opts = {method: 'get', action: 'model/' + id + '/status', id: id};
+ var status_changed = $.ajax({
+ type: opts.method,
+ url: opts.action,
+ async: false,
+ dataType: 'html',
+ data: {
+ '_method': 'get'
+ },
+ success: function(data) {
+ var erg = data.search(/started/);
+ status_changed = false;
+ if(erg < 0) status_changed = true;
+ $("span#model_" + id + "_status").animate({"opacity": "0.1"},1000);
+ $("span#model_" + id + "_status").animate({"opacity": "1"},1000);
+ if( status_changed ) {
+ $("span#model_" + id + "_status").html(data);
+ loadModel(id);
+ id = -1;
+ }
+ },
+ error: function(data) {
+ alert("status check error");
+ }
+ });
+ return id;
+ };
+
+ loadModel = function(id) {
+ if(id == "") return -1;
+ var opts = {method: 'get', action: 'model/' + id };
+ var out = id;
+ $.ajax({
+ type: opts.method,
+ url: opts.action,
+ dataType: 'html',
+ data: {
+ '_method': 'get'
+ },
+ success: function(data) {
+ $("div#model_" + id).animate({"opacity": "0.1"},1000).delay(100);
+ $("div#model_" + id).html(data);
+ $("div#model_" + id).animate({"opacity": "1"},1000).delay(100);
+ },
+ error: function(data) {
+ alert("loadModel error");
+ }
+ });
+ return false;
+ };
+
+
+});
+
+jQuery.fn.deleteModel = function(type, options) {
+ var defaults = {
+ method: 'post',
+ action: this.attr('href'),
+ confirm_message: 'Are you sure?',
+ trigger_on: 'click'
+ };
+ var opts = $.extend(defaults, options);
+ this.bind(opts.trigger_on, function() {
+ if(confirm(opts.confirm_message)) {
+ $.ajax({
+ type: opts.method,
+ url: opts.action,
+ dataType: 'html',
+ data: {
+ '_method': 'delete'
+ },
+ success: function(data) {
+ $(opts.elem).fadeTo("slow",0).slideUp("slow");
+ },
+ error: function(data) {
+ alert("model delete error!");
+ }
+ });
+ }
+ return false;
+ });
+};
+
+