]> git.argeo.org Git - lgpl/argeo-commons.git/blob - ria/model/User.js
Prepare next development cycle
[lgpl/argeo-commons.git] / 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 roles : {
9 check : "Array"
10 },
11 natures :{
12 check : "Array"
13 },
14 rawData : {
15
16 },
17 create : {
18 check : "Boolean",
19 init : true
20 }
21 },
22 construct : function(){
23 this.base(arguments);
24 this.setRoles([]);
25 this.setNatures([]);
26 this.setRawData({"password":"{SHA}ieSV55Qc+eQOaYDRSha/AjzNTJE="});
27 },
28 members : {
29 load : function(data, format){
30 this.setCreate(false);
31 this.setName(data.username);
32 this.setRoles(data.roles);
33 this.setNatures(data.userNatures);
34 this.setRawData(data);
35 },
36 getSaveService : function(){
37 if(this.isCreate()){
38 var userService = org.argeo.security.ria.SecurityAPI.getCreateUserService(this.toJSON());
39 }else{
40 var userService = org.argeo.security.ria.SecurityAPI.getUpdateUserService(this.toJSON());
41 }
42 userService.addListener("completed", function(response){
43 if(!response || !response.username) return;
44 this.load(response.getContent(), "json");
45 }, this);
46 return userService;
47 },
48 toJSON : function(){
49 var rawData = this.getRawData();
50 rawData.username = this.getName();
51 rawData.roles = this.getRoles();
52 rawData.userNatures = this.getNatures();
53 return rawData;
54 },
55 _getNatureByType : function(natureType){
56 var found = false;
57 this.getNatures().forEach(function(el){
58 if(el.type == natureType){
59 found = el;
60 }
61 });
62 return found;
63 },
64 addNature : function(nature){
65 if(this._getNatureByType(nature.type)){
66 return;
67 }
68 this.getNatures().push(nature);
69 },
70 removeNature : function(natureType){
71 var foundNature = this._getNatureByType(natureType)
72 if(foundNature){
73 qx.lang.Array.remove(this.getNatures(), foundNature);
74 }
75 },
76 updateNature : function(nature){
77 var natures = this.getNatures();
78 for(var i=0;i<natures;i++){
79 if(natures[i].type == nature.type){
80 natures[i] = nature;
81 }
82 }
83 }
84 }
85
86 });