/* * To change this template, choose Tools | Templates * and open the template in the editor. */ var global_load = null; !function($) { $(function() { $body = $("body"); $(document).on({ ajaxStart: function() { $body.addClass("loading"); }, ajaxStop: function() { $body.removeClass("loading"); } }); function event(where){ $("#alert .alert").alert(); $(where+'.dropdown-toggle').dropdown(); $(where+" a").each(function(that){ if($(this).attr("rel")!=="external") $(this).click(function(e){ load($(this).attr('href'),{},($(this).attr('rel')=="tab")); return false; }); }); $(where+" form").submit(function(e){ if(!$(this).hasClass("hide-form") && $(this).attr('enctype')!='multipart/form-data' ){ e.stopPropagation(); //e.preventDefault(); if($(this).attr("back")) back=window.location.href; else back=null; load($(this).attr("action"),{data:$(this).serialize(), type:$(this).attr("method"),back:back},($(this).attr('rel')=="tab")); return false; } }); $("form[ enctype *= 'multipart/form-data' ]").each(function(evt){ if (!$('#fileUpload').length) $('body').append(''); $(this).attr('target','fileUpload'); $(this).submit(function(){ frame = $('#fileUpload').load(function(){ setContent(frame.contents().find('body').html()); frame.unbind('load'); setTimeout(function (){frame.html('');}, 1); }); }); }); $(where+" form.hide-form").each(function(evt){ that = this; $('span.edit.label',this).click(function(evt){ $(that).removeClass('hide-input'); $(this).addClass('hide'); $('span.save.label',that).removeClass('hide'); $('input',that).removeAttr('disabled'); }); function handleSend(evt){ that2=this; $.getJSON($(that).attr("action"),$(that).serialize(),function(evt){ if(!evt.error){ $(that).addClass('hide-input'); $('input',that).attr('disabled','disabled'); $('span.save.label',that).addClass('hide'); $('span.edit.label',that).removeClass('hide'); }else{ //TODO Handle error console.log("TODO Handle Error"); } }); } $('span.save.label',this).addClass('hide'); $('input',this).attr('disabled','disabled'); $('span.save.label',this).click(handleSend); $(that).submit(function(evt){ evt.stopPropagation(); handleSend(evt); return false; }); }); //$(where+" form label.has-error").parent(".form-group").addClass("has-error") } function setContent(data,back,tab){ alert = data.split('')[1].split('')[0]; if( alert.trim().length > 0){ $('#alert').html(alert); } if(back){ load(back,{},tab); }else if(tab){ navbar = data.split('')[1].split('')[0]; $('#tab').html(navbar); event("#tab"); }else{ navbar = data.split('')[1].split('')[0]; $('#navbar').html(navbar); event("#navbar"); container = data.split('')[1].split('')[0]; $('#container').html(container); event("#container"); barright = data.split('')[1].split('')[0]; $('#barright').html(barright); event("#barright"); barleft = data.split('')[1].split('')[0]; $('#barleft').html(barleft); event("#barleft"); } if(!back){ navbar = data.split('')[1].split('')[0]; eval($(navbar).html()); } } function setContentError(data,back,tab){ alert = "