Diffstat (limited to 'frontend/beta/js/Clipperz/PM/Components/RecordDetail/NotesComponent.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/PM/Components/RecordDetail/NotesComponent.js | 240 |
1 files changed, 240 insertions, 0 deletions
diff --git a/frontend/beta/js/Clipperz/PM/Components/RecordDetail/NotesComponent.js b/frontend/beta/js/Clipperz/PM/Components/RecordDetail/NotesComponent.js new file mode 100644 index 0000000..6f454fc --- a/dev/null +++ b/frontend/beta/js/Clipperz/PM/Components/RecordDetail/NotesComponent.js | |||
@@ -0,0 +1,240 @@ | |||
1 | /* | ||
2 | |||
3 | Copyright 2008-2011 Clipperz Srl | ||
4 | |||
5 | This file is part of Clipperz's Javascript Crypto Library. | ||
6 | Javascript Crypto Library provides web developers with an extensive | ||
7 | and efficient set of cryptographic functions. The library aims to | ||
8 | obtain maximum execution speed while preserving modularity and | ||
9 | reusability. | ||
10 | For further information about its features and functionalities please | ||
11 | refer 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 | |||
29 | if (typeof(Clipperz) == 'undefined') { Clipperz = {}; } | ||
30 | if (typeof(Clipperz.PM) == 'undefined') { Clipperz.PM = {}; } | ||
31 | if (typeof(Clipperz.PM.Components) == 'undefined') { Clipperz.PM.Components = {}; } | ||
32 | if (typeof(Clipperz.PM.Components.RecordDetail) == 'undefined') { Clipperz.PM.Components.RecordDetail = {}; } | ||
33 | |||
34 | //############################################################################# | ||
35 | |||
36 | |||
37 | |||
38 | Clipperz.PM.Components.RecordDetail.NotesComponent = function(anElement, args) { | ||
39 | //MochiKit.Logging.logDebug(">>> new NotesComponent"); | ||
40 | args = args || {}; | ||
41 | |||
42 | Clipperz.PM.Components.RecordDetail.NotesComponent.superclass.constructor.call(this, anElement, args); | ||
43 | |||
44 | this.mainComponent().addEditComponent(this); | ||
45 | |||
46 | this._staticOffset = null; | ||
47 | this._componentHeight = 50; | ||
48 | this._mouseMoveIdentifier = null; | ||
49 | this._mouseUpIdentifier = null; | ||
50 | |||
51 | this.element().setVisibilityMode(YAHOO.ext.Element.DISPLAY); | ||
52 | |||
53 | this.render(); | ||
54 | //MochiKit.Logging.logDebug("<<< new NotesComponent"); | ||
55 | |||
56 | return this; | ||
57 | } | ||
58 | |||
59 | //============================================================================= | ||
60 | |||
61 | YAHOO.extendX(Clipperz.PM.Components.RecordDetail.NotesComponent, Clipperz.PM.Components.RecordDetail.AbstractComponent, { | ||
62 | |||
63 | 'toString': function() { | ||
64 | return "Clipperz.PM.Components.RecordDetail.NotesComponent component"; | ||
65 | }, | ||
66 | |||
67 | //------------------------------------------------------------------------- | ||
68 | |||
69 | 'value': function() { | ||
70 | return this.record().notes(); | ||
71 | }, | ||
72 | |||
73 | 'setValue': function(aValue) { | ||
74 | this.record().setNotes(aValue); | ||
75 | }, | ||
76 | |||
77 | //------------------------------------------------------------------------- | ||
78 | |||
79 | 'render': function() { | ||
80 | //MochiKit.Logging.logDebug(">>> NotesComponent.render"); | ||
81 | /* | ||
82 | Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'td', colspan:'5', children:[ | ||
83 | {tag:'span', cls:'noteFieldLabel', htmlString:Clipperz.PM.Strings['recordDetailNotesLabel']}, | ||
84 | {tag:'div', cls:'noteFieldContent', id:this.getId('notes')} | ||
85 | ]}); | ||
86 | */ | ||
87 | Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'span', cls:'noteFieldLabel', htmlString:Clipperz.PM.Strings['recordDetailNotesLabel']}); | ||
88 | Clipperz.YUI.DomHelper.append(this.element().dom, {tag:'div', cls:'noteFieldContent', id:this.getId('notes'), children:[ | ||
89 | {tag:'div', id:this.getId('resizableDiv'), cls:'resizable-textarea', children:[ | ||
90 | {tag:'div', id:this.getId('contentView'), cls:'viewMode', html:""}, | ||
91 | {tag:'div', id:this.getId('contentEdit'), children:[ | ||
92 | {tag:'span', children:[ | ||
93 | {tag:'textarea', id:this.getId('textarea'), html:""} | ||
94 | ]} | ||
95 | ]}, | ||
96 | {tag:'div', id:this.getId('grippie'), cls:'grippie'} | ||
97 | ]} | ||
98 | ]}); | ||
99 | |||
100 | this.getElement('contentView').setVisibilityMode(YAHOO.ext.Element.DISPLAY); | ||
101 | this.getElement('contentEdit').setVisibilityMode(YAHOO.ext.Element.DISPLAY); | ||
102 | |||
103 | MochiKit.Signal.connect(this.getId('grippie'), 'onmousedown', this, 'startResize'); | ||
104 | |||
105 | this.update(); | ||
106 | //MochiKit.Logging.logDebug("<<< NotesComponent.render"); | ||
107 | }, | ||
108 | |||
109 | //------------------------------------------------------------------------- | ||
110 | |||
111 | 'updateViewMode': function() { | ||
112 | //MochiKit.Logging.logDebug(">>> NotesComponent.updateViewMode"); | ||
113 | // this.getElement('notes').update(this.value().replace(/\n/g, '<br>')); | ||
114 | |||
115 | this.getElement('contentView').update(Clipperz.Base.sanitizeString(this.value()).replace(/\n/g, '<br>')); | ||
116 | |||
117 | if (this.isNoteEmpty()) { | ||
118 | this.element().hide(); | ||
119 | } else { | ||
120 | this.getElement('contentView').show(); | ||
121 | this.getElement('contentView').setHeight(this.componentHeight()); | ||
122 | } | ||
123 | this.getElement('contentEdit').hide(); | ||
124 | |||
125 | //MochiKit.Logging.logDebug("<<< NotesComponent.updateViewMode"); | ||
126 | }, | ||
127 | |||
128 | //------------------------------------------------------------------------- | ||
129 | |||
130 | 'updateEditMode': function() { | ||
131 | //MochiKit.Logging.logDebug(">>> NotesComponent.updateEditMode"); | ||
132 | this.getDom('textarea').value = this.value().replace(/\n/g, Clipperz_normalizedNewLine); | ||
133 | |||
134 | this.getElement('contentView').hide(); | ||
135 | this.getElement('contentEdit').show(); | ||
136 | |||
137 | this.getElement('textarea').setHeight(this.componentHeight()); | ||
138 | //MochiKit.Logging.logDebug("<<< NotesComponent.updateEditMode"); | ||
139 | }, | ||
140 | |||
141 | //------------------------------------------------------------------------- | ||
142 | |||
143 | 'synchronizeComponentValues': function() { | ||
144 | //MochiKit.Logging.logDebug(">>> NotesComponent.synchronizeComponentValues"); | ||
145 | if (this.getElement('textarea') != null) { | ||
146 | this.setValue(this.getDom('textarea').value.replace(/(\x0a\x0d|\x0d\x0a)/g,'\n')); | ||
147 | } | ||
148 | //MochiKit.Logging.logDebug("<<< NotesComponent.synchronizeComponentValues"); | ||
149 | }, | ||
150 | |||
151 | //------------------------------------------------------------------------- | ||
152 | |||
153 | 'componentHeight': function() { | ||
154 | return this._componentHeight; | ||
155 | }, | ||
156 | |||
157 | 'setComponentHeight': function(aValue) { | ||
158 | this._componentHeight = aValue; | ||
159 | }, | ||
160 | |||
161 | //------------------------------------------------------------------------- | ||
162 | |||
163 | 'isNoteEmpty': function() { | ||
164 | return !/[^ \n]/.test(this.value()); | ||
165 | }, | ||
166 | |||
167 | //------------------------------------------------------------------------- | ||
168 | |||
169 | 'staticOffset': function() { | ||
170 | return this._staticOffset; | ||
171 | }, | ||
172 | |||
173 | 'setStaticOffset': function(aValue) { | ||
174 | this._staticOffset = aValue; | ||
175 | }, | ||
176 | |||
177 | //------------------------------------------------------------------------- | ||
178 | |||
179 | 'startResize': function(anEvent) { | ||
180 | //MochiKit.Logging.logDebug(">>> startResize"); | ||
181 | if (this.editMode() == 'VIEW') { | ||
182 | this.setStaticOffset(this.getElement('contentView').getHeight() - anEvent.mouse().page['y']) | ||
183 | } else { | ||
184 | this.setStaticOffset(this.getElement('textarea').getHeight() - anEvent.mouse().page['y']) | ||
185 | // this.getElement('textarea').setStyle('opacity', 0.25); | ||
186 | } | ||
187 | this.setMouseMoveIdentifier(MochiKit.Signal.connect(MochiKit.DOM.currentDocument(), 'onmousemove', this, 'whileResizing')); | ||
188 | this.setMouseUpIdentifier(MochiKit.Signal.connect(MochiKit.DOM.currentDocument(), 'onmouseup', this, 'endResize')); | ||
189 | anEvent.stop(); | ||
190 | //MochiKit.Logging.logDebug("<<< startResize"); | ||
191 | }, | ||
192 | |||
193 | //------------------------------------------------------------------------- | ||
194 | |||
195 | 'whileResizing': function(anEvent) { | ||
196 | //MochiKit.Logging.logDebug(">>> whileResizing"); | ||
197 | this.getElement('textarea').setHeight(Math.max(32, this.staticOffset() + anEvent.mouse().page['y']) + 'px'); | ||
198 | this.getElement('contentView').setHeight(Math.max(32, this.staticOffset() + anEvent.mouse().page['y']) + 'px'); | ||
199 | anEvent.stop(); | ||
200 | //MochiKit.Logging.logDebug("<<< whileResizing"); | ||
201 | }, | ||
202 | |||
203 | //------------------------------------------------------------------------- | ||
204 | |||
205 | 'endResize': function(anEvent) { | ||
206 | //MochiKit.Logging.logDebug(">>> endResize"); | ||
207 | MochiKit.Signal.disconnect(this.mouseMoveIdentifier()); | ||
208 | this.setMouseMoveIdentifier(null); | ||
209 | MochiKit.Signal.disconnect(this.mouseUpIdentifier()); | ||
210 | this.setMouseUpIdentifier(null); | ||
211 | // this.getElement('textarea').setStyle('opacity', 1); | ||
212 | |||
213 | this.setComponentHeight(this.getElement('textarea').getHeight()); | ||
214 | //MochiKit.Logging.logDebug("<<< endResize"); | ||
215 | }, | ||
216 | |||
217 | //------------------------------------------------------------------------- | ||
218 | |||
219 | 'mouseMoveIdentifier': function() { | ||
220 | return this._mouseMoveIdentifier; | ||
221 | }, | ||
222 | |||
223 | 'setMouseMoveIdentifier': function(aValue) { | ||
224 | this._mouseMoveIdentifier = aValue; | ||
225 | }, | ||
226 | |||
227 | //------------------------------------------------------------------------- | ||
228 | |||
229 | 'mouseUpIdentifier': function() { | ||
230 | return this._mouseUpIdentifier; | ||
231 | }, | ||
232 | |||
233 | 'setMouseUpIdentifier': function(aValue) { | ||
234 | this._mouseUpIdentifier = aValue; | ||
235 | }, | ||
236 | |||
237 | //------------------------------------------------------------------------- | ||
238 | __syntaxFix__: "syntax fix" | ||
239 | }); | ||
240 | |||