/static/scripts/packed/mvc/user/user-model.js

https://bitbucket.org/hbc/galaxy-central-hbc/ · JavaScript · 1 lines · 1 code · 0 blank · 0 comment · 0 complexity · d00115a013c0447b348726b3aa2b8694 MD5 · raw file

  1. define(["mvc/base-mvc","utils/localization"],function(a,b){var d=Backbone.Model.extend(a.LoggableMixin).extend({urlRoot:galaxy_config.root+"api/users",defaults:{id:null,username:"("+b("anonymous user")+")",email:"",total_disk_usage:0,nice_total_disk_usage:"",quota_percent:null,is_admin:false},initialize:function(e){this.log("User.initialize:",e);this.on("loaded",function(f,g){this.log(this+" has loaded:",f,g)});this.on("change",function(f,g){this.log(this+" has changed:",f,g.changes)})},isAnonymous:function(){return(!this.get("email"))},isAdmin:function(){return(this.get("is_admin"))},loadFromApi:function(h,f){h=h||d.CURRENT_ID_STR;f=f||{};var e=this,g=f.success;f.success=function(j,i){e.trigger("loaded",j,i);if(g){g(j,i)}};if(h===d.CURRENT_ID_STR){f.url=this.urlRoot+"/"+d.CURRENT_ID_STR}return Backbone.Model.prototype.fetch.call(this,f)},clearSessionStorage:function(){for(var e in sessionStorage){if(e.indexOf("history:")===0){sessionStorage.removeItem(e)}else{if(e==="history-panel"){sessionStorage.removeItem(e)}}}},toString:function(){var e=[this.get("username")];if(this.get("id")){e.unshift(this.get("id"));e.push(this.get("email"))}return"User("+e.join(":")+")"}});d.CURRENT_ID_STR="current";d.getCurrentUserFromApi=function(f){var e=new d();e.loadFromApi(d.CURRENT_ID_STR,f);return e};var c=Backbone.Collection.extend(a.LoggableMixin).extend({model:d,urlRoot:galaxy_config.root+"api/users"});return{User:d}});