summaryrefslogtreecommitdiff
path: root/frontend/beta/js/Clipperz/PM/DataModel/RecordField.js
blob: a5d7980df6a31cd95df0af8283e35653b9029ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*

Copyright 2008-2013 Clipperz Srl

This file is part of Clipperz, the online password manager.
For further information about its features and functionalities please
refer to http://www.clipperz.com.

* Clipperz is free software: you can redistribute it and/or modify it
  under the terms of the GNU Affero General Public License as published
  by the Free Software Foundation, either version 3 of the License, or 
  (at your option) any later version.

* Clipperz is distributed in the hope that it will be useful, but 
  WITHOUT ANY WARRANTY; without even the implied warranty of 
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  See the GNU Affero General Public License for more details.

* You should have received a copy of the GNU Affero General Public
  License along with Clipperz. If not, see http://www.gnu.org/licenses/.

*/

if (typeof(Clipperz) == 'undefined') { Clipperz = {}; }
if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; }
if (typeof(Clipperz.PM.DataModel) == 'undefined') { Clipperz.PM.DataModel = {}; }

//#############################################################################

Clipperz.PM.DataModel.RecordField = function(args) {
	args = args || {};

	this._recordVersion = args.recordVersion || null;
	this._key	 = args.key	   || Clipperz.PM.Crypto.randomKey();
	this.setLabel(args.label  || '');
	this.setValue(args.value  || '');
	this.setType(args.type   || 'TXT');	//	valid types: 'TXT', 'PWD', 'URL', 'DATE', 'ADDR', 'CHECK', 'RADIO', ('NOTE' probably not), ...
	this._hidden = args.hidden || (args.type == 'PWD') || false;

	return this;
}

Clipperz.PM.DataModel.RecordField.prototype = MochiKit.Base.update(null, {

	'toString': function() {
		return "Clipperz.PM.DataModel.RecordField - " + this.label() + " (" + this.key() + ")";
	},

	//-------------------------------------------------------------------------

	'recordVersion': function() {
		return this._recordVersion;
	},

	//-------------------------------------------------------------------------

	'key': function() {
		return this._key;
	},

	//-------------------------------------------------------------------------

	'label': function() {
		return this._label;
	},
	
	'setLabel': function(aValue) {
		this._label = aValue;
	},
	
	//-------------------------------------------------------------------------

	'value': function() {
		return this._value;
	},
	
	'setValue': function(aValue) {
		this._value = aValue;
	},
	
	//-------------------------------------------------------------------------

	'type': function() {
		return this._type;
	},
	
	'setType': function(aValue) {
		this._type = aValue;
		
		if (aValue == 'PWD') {
			this.setHidden(true);
		} else {
			this.setHidden(false);
		}
	},
	
	//-------------------------------------------------------------------------

	'serializeData': function() {
		var result;
		
//MochiKit.Logging.logDebug(">>> RecordField.serializeData - " + this);
		result = {
			label:  this.label(),
			value:	this.value(),
			type:   this.type(),
			hidden: this.hidden()
		};
//MochiKit.Logging.logDebug("<<< RecordField.serializeData");

		return result;
	},
	
	//-------------------------------------------------------------------------

	'typeShortDescription': function() {
//		return Clipperz.PM.DataModel.RecordField.TypeDescriptions[this.type()]['shortDescription'];
		return Clipperz.PM.Strings['recordFieldTypologies'][this.type()]['shortDescription'];
	},

	//-------------------------------------------------------------------------

	'hidden': function() {
		return this._hidden;
	},
	
	'setHidden': function(aValue) {
		this._hidden = aValue;
	},

	//-------------------------------------------------------------------------

	'clone': function(aRecordVersion) {
		var result;

		result = new Clipperz.PM.DataModel.RecordField({
			recordVersion:aRecordVersion,
			label:this.label(),
			value:this.value(),
			type:this.type(),
			hidden:this.hidden()
		});
		
		return result;
	},

	//-------------------------------------------------------------------------

	'isEmpty': function() {
		var result;
		
		if ((this.label() == "") && (this.value() == "") && (this.type() == 'TXT')) {
			result = true;
		} else {
			result = false;
		}
		
		return result;
	},
	
	//-------------------------------------------------------------------------
	__syntaxFix__: "syntax fix"
	
});

//#############################################################################
/*
Clipperz.PM.DataModel.RecordField.TypeDescriptions = {
	'TXT': {
		description: 'simple text field',
		shortDescription: 'txt'
	},
	'PWD': {
		description: 'simple text field, with default status set to hidden',
		shortDescription: 'pwd'
	},
	'URL': {
		description: 'simple text field in edit mode, that became an active url in view mode',
		shortDescription: 'url'
	},
	'DATE': {
		description: 'a value set with a calendar helper',
		shortDescription: 'date'
	},
	'ADDR': {
		description: 'just like the URL, but the active link points to Google Maps (or similar service) passing the address value as argument',
		shortDescription: 'addr'
	},
	'CHECK': {
		description: 'check description',
		shortDescription: 'check'
	},
	'RADIO': {
		description: 'radio description',
		shortDescription: 'radio'
	},
	'SELECT': {
		description: 'select description',
		shortDescription: 'select'
	}
	
//	'NOTE': {
//		description: 'a simple text field, but with a bigger component dimension; possibly with "smart edit components"',
//		shortDescription: 'note'
//	}
};

Clipperz.PM.DataModel.RecordField.InputTypeToRecordFieldType = {
	'text': 'TXT',
	'password': 'PWD',
	'checkbox': 'CHECK',
	'radio': 'RADIO',
	'select': 'SELECT'
};
*/