summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.Field.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.Field.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.Field.js167
1 files changed, 167 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.Field.js b/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.Field.js
new file mode 100644
index 0000000..147aa7d
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/DataModel/Record.Version.Field.js
@@ -0,0 +1,167 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz's Javascript Crypto Library.
6Javascript Crypto Library provides web developers with an extensive
7and efficient set of cryptographic functions. The library aims to
8obtain maximum execution speed while preserving modularity and
9reusability.
10For further information about its features and functionalities please
11refer to http://www.clipperz.com
12
13* Javascript Crypto Library is free software: you can redistribute
14 it and/or modify it under the terms of the GNU Affero General Public
15 License as published by the Free Software Foundation, either version
16 3 of the License, or (at your option) any later version.
17
18* Javascript Crypto Library is distributed in the hope that it will
19 be useful, but WITHOUT ANY WARRANTY; without even the implied
20 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
21 See the GNU Affero General Public License for more details.
22
23* You should have received a copy of the GNU Affero General Public
24 License along with Javascript Crypto Library. If not, see
25 <http://www.gnu.org/licenses/>.
26
27*/
28
29try { if (typeof(Clipperz.PM.DataModel.Record.Version) == 'undefined') { throw ""; }} catch (e) {
30 throw "Clipperz.PM.DataModel.Record.Version.Field depends on Clipperz.PM.DataModel.Record.Version!";
31}
32
33Clipperz.PM.DataModel.Record.Version.Field = function(args) {
34 Clipperz.PM.DataModel.Record.Version.Field.superclass.constructor.apply(this, arguments);
35
36 this._recordVersion = args.recordVersion|| Clipperz.Base.exception.raise('MandatoryParameter');
37 this._reference = args.reference || Clipperz.PM.Crypto.randomKey();
38
39 return this;
40}
41
42
43Clipperz.Base.extend(Clipperz.PM.DataModel.Record.Version.Field, Object, {
44
45 'toString': function() {
46 return "Record.Version.Field (" + this.reference() + ")";
47 },
48
49 //-------------------------------------------------------------------------
50
51 'recordVersion': function () {
52 return this._recordVersion;
53 },
54
55 //-------------------------------------------------------------------------
56
57 'reference': function () {
58 return this._reference;
59 },
60
61 //-------------------------------------------------------------------------
62
63 'getItem': function (aKey) {
64 return Clipperz.Async.callbacks("Clipperz.PM.DataModel.Record.Version.Field.getItem", [
65 MochiKit.Base.method(this, 'recordVersion'),
66 MochiKit.Base.methodcaller('getValue', 'fields' + '.' + this.reference() + '.' + aKey)
67 ], {trace:false});
68 },
69
70 'setItem': function (aKey, aValue) {
71 return Clipperz.Async.callbacks("Clipperz.PM.DataModel.Record.Version.Field.getItem", [
72 MochiKit.Base.method(this, 'recordVersion'),
73 MochiKit.Base.methodcaller('setValue', 'fields' + '.' + this.reference() + '.' + aKey, aValue)
74 ], {trace:false});
75 },
76
77 //-------------------------------------------------------------------------
78
79 'label': function () {
80 return this.getItem('label');
81 },
82
83 'setLabel': function (aValue) {
84 return this.setItem('label', aValue);
85 },
86
87 //-------------------------------------------------------------------------
88
89 'value': function () {
90 return this.getItem('value');
91 },
92
93 'setValue': function (aValue) {
94 return this.setItem('value', aValue);
95 },
96
97 //-------------------------------------------------------------------------
98
99 'actionType': function () {
100 return Clipperz.Async.callbacks("Clipperz.PM.DataModel.Record.Version.Field.actionType", [
101 Clipperz.Async.collectResults("Clipperz.PM.DataModel.Record.Version.Field.actionType [collect results]", {
102 'isHidden':MochiKit.Base.method(this, 'isHidden'),
103 'value':MochiKit.Base.method(this, 'value')
104 }, {trace:false}),
105 function (someValues) {
106 var result; //'NONE', 'URL', 'EMAIL', 'PASSWORD'
107
108 result = 'NONE';
109
110 if (someValues['isHidden']) {
111 result = 'PASSWORD';
112 } else if (Clipperz.Base.isUrl(someValues['value'])) {
113 result = 'URL'
114 } else if (Clipperz.Base.isEmail(someValues['value'])) {
115 result = 'EMAIL'
116 };
117
118 return result;
119 }
120 ], {trace:false});
121 },
122
123 //-------------------------------------------------------------------------
124
125 'isHidden': function () {
126 return this.getItem('hidden');
127 },
128
129 'setIsHidden': function (aValue) {
130 return this.setItem('hidden', aValue);
131 },
132
133 //-------------------------------------------------------------------------
134
135 'isEmpty': function () {
136 var deferredResult;
137
138 deferredResult = new Clipperz.Async.Deferred("Clipperz.PM.DataModel.Record.Version.Field.isEmpty", {trace:false});
139
140 deferredResult.collectResults({
141 'label': [
142 MochiKit.Base.method(this, 'label'),
143 MochiKit.Base.partial(MochiKit.Base.operator.eq, '')
144 ],
145 'value': [
146 MochiKit.Base.method(this, 'value'),
147 MochiKit.Base.partial(MochiKit.Base.operator.eq, '')
148 ],
149 'isHidden': [
150 MochiKit.Base.method(this, 'isHidden'),
151 MochiKit.Base.partial(MochiKit.Base.operator.eq, false)
152 ]
153 });
154 deferredResult.addCallback(MochiKit.Base.values);
155 deferredResult.addCallback(function(someValues) {
156 return MochiKit.Iter.every(someValues, MochiKit.Base.operator.identity);
157 });
158 deferredResult.callback();
159
160 return deferredResult;
161 },
162
163 //-------------------------------------------------------------------------
164 __syntaxFix__: "syntax fix"
165});
166
167