-qx.Class.define("org.argeo.security.ria.model.User", {\r
- extend : qx.core.Object,\r
- properties : {\r
- name : {\r
- init : "",\r
- check : "String"\r
- },\r
- password : {\r
- nullable : true,\r
- check : "String"\r
- },\r
- roles : {\r
- check : "Array"\r
- },\r
- natures :{\r
- check : "Array"\r
- },\r
- rawData : {\r
- \r
- },\r
- create : {\r
- check : "Boolean",\r
- init : true\r
- }\r
- },\r
- construct : function(){\r
- this.base(arguments);\r
- this.setRoles([]);\r
- this.setNatures([]);\r
- this.setRawData({password:null});\r
- },\r
- members : {\r
- load : function(data, format){\r
- this.setCreate(false);\r
- this.setName(data.username);\r
- this.setRoles(data.roles);\r
- this.setNatures(data.userNatures);\r
- this.setRawData(data);\r
- },\r
- getSaveService : function(self){\r
- if(this.isCreate()){\r
- var userService = org.argeo.security.ria.SecurityAPI.getCreateUserService(this.toJSON(true)); \r
- }else{\r
- var userService = org.argeo.security.ria.SecurityAPI.getUpdateUserService(this.toJSON(), self); \r
- }\r
- userService.addListener("completed", function(response){\r
- if(!response || !response.username) return;\r
- this.load(response.getContent(), "json");\r
- }, this);\r
- return userService; \r
- },\r
- toJSON : function(create){\r
- var rawData = this.getRawData();\r
- rawData.username = this.getName();\r
- rawData.roles = this.getRoles();\r
- rawData.userNatures = this.getNatures();\r
- if(create) rawData.password = this.getPassword();\r
- return rawData;\r
- },\r
- _getNatureByType : function(natureType){\r
- var found = false;\r
- this.getNatures().forEach(function(el){\r
- if(el.type == natureType){\r
- found = el;\r
- }\r
- }); \r
- return found;\r
- },\r
- addNature : function(nature){\r
- if(this._getNatureByType(nature.type)){\r
- return;\r
- }\r
- this.getNatures().push(nature);\r
- },\r
- removeNature : function(natureType){\r
- var foundNature = this._getNatureByType(natureType)\r
- if(foundNature){\r
- qx.lang.Array.remove(this.getNatures(), foundNature);\r
- }\r
- },\r
- updateNature : function(nature){\r
- var natures = this.getNatures();\r
- for(var i=0;i<natures;i++){\r
- if(natures[i].type == nature.type){\r
- natures[i] = nature;\r
- }\r
- }\r
- }\r
- }\r
- \r
-});
\ No newline at end of file