mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-24 23:49:37 +08:00
1 line
2.7 KiB
JavaScript
1 line
2.7 KiB
JavaScript
define(["utils/add-logging"],function(c){var d={logger:null,_logNamespace:"?",log:function(){if(this.logger){var e=this.logger.log;if(typeof this.logger.log==="object"){e=Function.prototype.bind.call(this.logger.log,this.logger)}return e.apply(this.logger,arguments)}return undefined}};c(d);var a=Backbone.Model.extend({initialize:function(f){this._checkEnabledSessionStorage();if(!f.id){throw new Error("SessionStorageModel requires an id in the initial attributes")}this.id=f.id;var e=(!this.isNew())?(this._read(this)):({});this.clear({silent:true});this.save(_.extend({},this.defaults,e,f),{silent:true});this.on("change",function(){this.save()})},_checkEnabledSessionStorage:function(){try{return sessionStorage.length}catch(e){alert("Please enable cookies in your browser for this Galaxy site");return false}},sync:function(h,f,e){if(!e.silent){f.trigger("request",f,{},e)}var g;switch(h){case"create":g=this._create(f);break;case"read":g=this._read(f);break;case"update":g=this._update(f);break;case"delete":g=this._delete(f);break}if(g!==undefined||g!==null){if(e.success){e.success()}}else{if(e.error){e.error()}}return g},_create:function(e){var f=e.toJSON(),g=sessionStorage.setItem(e.id,JSON.stringify(f));return(g===null)?(g):(f)},_read:function(e){return JSON.parse(sessionStorage.getItem(e.id))},_update:function(e){return e._create(e)},_delete:function(e){return sessionStorage.removeItem(e.id)},isNew:function(){return !sessionStorage.hasOwnProperty(this.id)},_log:function(){return JSON.stringify(this.toJSON(),null," ")},toString:function(){return"SessionStorageModel("+this.id+")"}});(function(){a.prototype=_.omit(a.prototype,"url","urlRoot")}());var b={hiddenUntilActivated:function(e,g){g=g||{};this.HUAVOptions={$elementShown:this.$el,showFn:jQuery.prototype.toggle,showSpeed:"fast"};_.extend(this.HUAVOptions,g||{});this.HUAVOptions.hasBeenShown=this.HUAVOptions.$elementShown.is(":visible");this.hidden=this.isHidden();if(e){var f=this;e.on("click",function(h){f.toggle(f.HUAVOptions.showSpeed)})}},isHidden:function(){return(this.HUAVOptions.$elementShown.is(":hidden"))},toggle:function(){if(this.hidden){if(!this.HUAVOptions.hasBeenShown){if(_.isFunction(this.HUAVOptions.onshowFirstTime)){this.HUAVOptions.hasBeenShown=true;this.HUAVOptions.onshowFirstTime.call(this)}}if(_.isFunction(this.HUAVOptions.onshow)){this.HUAVOptions.onshow.call(this);this.trigger("hiddenUntilActivated:shown",this)}this.hidden=false}else{if(_.isFunction(this.HUAVOptions.onhide)){this.HUAVOptions.onhide.call(this);this.trigger("hiddenUntilActivated:hidden",this)}this.hidden=true}return this.HUAVOptions.showFn.apply(this.HUAVOptions.$elementShown,arguments)}};return{LoggableMixin:d,SessionStorageModel:a,HiddenUntilActivatedViewMixin:b}}); |