]> 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
add description field
[lgpl/argeo-commons.git] / 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,
3 properties : {
4 name : {
5 init : "",
6 check : "String"
7 },
8 password : {
9 nullable : true,
10 check : "String"
11 },
12 roles : {
13 check : "Array"
14 },
15 natures :{
16 check : "Array"
17 },
18 rawData : {
19
20 },
21 create : {
22 check : "Boolean",
23 init : true
24 }
25 },
26 construct : function(){
27 this.base(arguments);
28 this.setRoles([]);
29 this.setNatures([]);
30 this.setRawData({password:null});
31 },
32 members : {
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);
39 },
40 getSaveService : function(){
41 if(this.isCreate()){
42 var userService = org.argeo.security.ria.SecurityAPI.getCreateUserService(this.toJSON(true));
43 }else{
44 var userService = org.argeo.security.ria.SecurityAPI.getUpdateUserService(this.toJSON());
45 }
46 userService.addListener("completed", function(response){
47 if(!response || !response.username) return;
48 this.load(response.getContent(), "json");
49 }, this);
50 return userService;
51 },
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();
58 return rawData;
59 },
60 _getNatureByType : function(natureType){
61 var found = false;
62 this.getNatures().forEach(function(el){
63 if(el.type == natureType){
64 found = el;
65 }
66 });
67 return found;
68 },
69 addNature : function(nature){
70 if(this._getNatureByType(nature.type)){
71 return;
72 }
73 this.getNatures().push(nature);
74 },
75 removeNature : function(natureType){
76 var foundNature = this._getNatureByType(natureType)
77 if(foundNature){
78 qx.lang.Array.remove(this.getNatures(), foundNature);
79 }
80 },
81 updateNature : function(nature){
82 var natures = this.getNatures();
83 for(var i=0;i<natures;i++){
84 if(natures[i].type == nature.type){
85 natures[i] = nature;
86 }
87 }
88 }
89 }
90
91 });