]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - security/runtime/org.argeo.security.ria/src/argeo-ria-lib/security/class/org/argeo/security/ria/model/User.js
1 qx
.Class
.define("org.argeo.security.ria.model.User", {
2 extend
: qx
.core
.Object
,
26 construct : function(){
30 this.setRawData({password
:null});
33 load : function(data
, format
){
34 this.setCreate(false);
35 this.setName(data
.username
);
36 this.setRoles(data
.roles
);
37 this.setNatures(data
.userNatures
);
38 this.setRawData(data
);
40 getSaveService : function(){
42 var userService
= org
.argeo
.security
.ria
.SecurityAPI
.getCreateUserService(this.toJSON(true));
44 var userService
= org
.argeo
.security
.ria
.SecurityAPI
.getUpdateUserService(this.toJSON());
46 userService
.addListener("completed", function(response
){
47 if(!response
|| !response
.username
) return;
48 this.load(response
.getContent(), "json");
52 toJSON : function(create
){
53 var rawData
= this.getRawData();
54 rawData
.username
= this.getName();
55 rawData
.roles
= this.getRoles();
56 rawData
.userNatures
= this.getNatures();
57 if(create
) rawData
.password
= this.getPassword();
60 _getNatureByType : function(natureType
){
62 this.getNatures().forEach(function(el
){
63 if(el
.type
== natureType
){
69 addNature : function(nature
){
70 if(this._getNatureByType(nature
.type
)){
73 this.getNatures().push(nature
);
75 removeNature : function(natureType
){
76 var foundNature
= this._getNatureByType(natureType
)
78 qx
.lang
.Array
.remove(this.getNatures(), foundNature
);
81 updateNature : function(nature
){
82 var natures
= this.getNatures();
83 for(var i
=0;i
<natures
;i
++){
84 if(natures
[i
].type
== nature
.type
){