summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/CardsController.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/CardsController.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/CardsController.js207
1 files changed, 207 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/CardsController.js b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/CardsController.js
new file mode 100644
index 0000000..b1a34b2
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/UI/Web/Controllers/CardsController.js
@@ -0,0 +1,207 @@
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
29Clipperz.Base.module('Clipperz.PM.UI.Web.Controllers');
30
31Clipperz.PM.UI.Web.Controllers.CardsController = function() {
32 Clipperz.PM.UI.Web.Controllers.CardsController.superclass.constructor.apply(this, arguments);
33
34 MochiKit.Signal.connect(Clipperz.Signal.NotificationCenter, 'cardDialogComponentClosed', this, 'handleHideCard');
35
36 return this;
37}
38
39Clipperz.Base.extend(Clipperz.PM.UI.Web.Controllers.CardsController, Clipperz.PM.UI.Web.Controllers.GridController, {
40
41 'toString': function() {
42 return "Clipperz.PM.UI.Web.Controllers.CardsController";
43 },
44
45 'createGrid': function () {
46 var grid;
47
48 grid = new Clipperz.PM.UI.Web.Components.GridComponent({columnsManagers: [
49 new Clipperz.PM.UI.Web.Components.FaviconColumnManager({
50 'name': 'Cards.favicon',
51 'selector': MochiKit.Base.methodcaller('favicon'),
52 'cssClass': 'favicon'
53 }),
54 new Clipperz.PM.UI.Web.Components.LinkColumnManager({
55 'name': 'Cards.title',
56 'selector': MochiKit.Base.methodcaller('label'),
57 'label': 'title',
58 'cssClass': 'title',
59 'comparator': Clipperz.Base.caseInsensitiveCompare,
60 'sortable': true,
61 'sorted': 'ASCENDING',
62 // 'actionMethod': function(anObject, anEvent) { MochiKit.Signal.signal(Clipperz.Signal.NotificationCenter, 'editCard', {objectData:anObject, element:anEvent.src()})}
63 'actionMethod': MochiKit.Base.method(this, 'handleShowCard')
64 }),
65 new Clipperz.PM.UI.Web.Components.DirectLoginsColumnManager({
66 'name': 'Cards.directLogins',
67 'selector': MochiKit.Base.methodcaller('directLoginReferences'),
68 'label': 'direct logins',
69 'cssClass': 'directLogin'
70 }),
71 new Clipperz.PM.UI.Web.Components.DateColumnManager({
72 'name': 'Cards.latestUpdate',
73 'selector': MochiKit.Base.methodcaller('updateDate'),
74 'label': 'latest update',
75 'cssClass': 'latestUpdate',
76 'format': 'd-m-Y',
77 'comparator': MochiKit.Base.compare,
78 'sortable': true,
79 'sorted': 'UNSORTED'
80 }),
81 new Clipperz.PM.UI.Web.Components.DeleteObjectColumnManager({
82 'name': 'Cards.delete',
83 'selector': MochiKit.Base.noop,
84 'cssClass': 'delete',
85 // 'actionMethod': function(anObject, anEvent) { MochiKit.Signal.signal(Clipperz.Signal.NotificationCenter, 'deleteCard', {objectData:anObject, element:anEvent.src()})}
86 'actionMethod': MochiKit.Base.method(this, 'handleDeleteCard')
87 })
88 ]});
89
90 grid.setComponentForSlotNamed(new Clipperz.PM.UI.Web.Components.BookmarkletComponent(), 'headerSlot');
91
92 return grid;
93 },
94
95 //-----------------------------------------------------------------------------
96
97 'getRows': function () {
98 //TODO relying on user() in GridController, bad code smell :|
99 return this.user().getRecords();
100 },
101
102 //=============================================================================
103
104 'displayEmptyContent': function () {
105 varemptyGridComponent;
106
107 emptyGridComponent = new Clipperz.PM.UI.Web.Components.CreateNewCardSplashComponent();
108
109 return Clipperz.Async.callbacks("CardsController.displayEmptyContent", [
110 MochiKit.Base.method(this.grid(), 'setNoRowsGridComponent', emptyGridComponent),
111 MochiKit.Base.bind(Clipperz.PM.UI.Web.Controllers.CardsController.superclass.displayEmptyContent, this)
112 ], {trace:false});
113 },
114
115 'displaySelectedRows': function (aFilter) {
116 this.columnManagerWithName('Cards.directLogins').hideDirectLoginListPopup();
117
118 return Clipperz.PM.UI.Web.Controllers.CardsController.superclass.displaySelectedRows.apply(this, arguments);
119 },
120
121 //=============================================================================
122
123 'handleShowCard': function (anObject, anEvent) {
124 var cardDialogController;
125
126 cardDialogController = new Clipperz.PM.UI.Web.Controllers.CardDialogController({record:anObject, delegate:this});
127 this.grid().selectRow(anObject);
128
129 cardDialogController.run(anEvent.src());
130 },
131
132 //.........................................................................
133
134 'handleHideCard': function () {
135 this.focus();
136 },
137
138 //-----------------------------------------------------------------------------
139
140 'addCard': function (aSourceElement) {
141 return Clipperz.Async.callbacks("CardsController.addCard", [
142 Clipperz.Async.collectResults("CardsController.addCard <inner results>", {
143 'record': MochiKit.Base.method(this.user(), 'createNewRecord'),
144 'delegate':MochiKit.Base.partial(MochiKit.Async.succeed, this)
145 }, {trace:false}),
146 function (someParameters) {
147 return new Clipperz.PM.UI.Web.Controllers.CardDialogController(someParameters);
148 },
149 MochiKit.Base.methodcaller('run', aSourceElement)
150 ], {trace:false});
151 },
152
153 //-----------------------------------------------------------------------------
154
155 'handleDeleteCard': function (anObject, anEvent) {
156 var deferredResult;
157 var confirmationDialog;
158
159 // confirmationDialog = new Clipperz.PM.UI.Common.Components.SimpleMessagePanel({
160 confirmationDialog = new Clipperz.PM.UI.Common.Components.MessagePanelWithProgressBar({
161 'title':"Delete Card",
162 'text': "Do you want to delete …",
163 'type': 'ALERT',
164 'buttons': [
165 {text:"Cancel",result:'CANCEL'},
166 {text:"Delete", result:'OK', isDefault:true}
167 ],
168 'canCancelWhileProcessing':false
169 });
170
171 deferredResult = new Clipperz.Async.Deferred("AppController.handleDeleteCard", {trace:false});
172 deferredResult.addCallback(MochiKit.Signal.signal, Clipperz.Signal.NotificationCenter, 'initProgress', {'steps':5}),
173 deferredResult.addMethod(this.grid(), 'selectRow', anObject);
174 deferredResult.addMethod(confirmationDialog, 'deferredShowModal', {
175 'openFromElement': anEvent.src(),
176 'onOkCloseToElement': null, //MochiKit.DOM.currentDocument().body,
177 'onCancelCloseToElement':anEvent.src()
178 });
179 // deferredResult.addCallback(function () { Clipperz.log("DELETE: " + anObject.toString(), anObject); });
180 deferredResult.addMethod(this.user(), 'deleteRecord', anObject);
181 deferredResult.addBothPass(MochiKit.Base.method(this.grid(), 'unselectRow', anObject));
182 deferredResult.addMethod(this, 'saveChanges');
183 deferredResult.addMethod(confirmationDialog, 'deferredDone');
184 deferredResult.addErrbackPass(function (anError) {
185 var result;
186
187 if (! (anError instanceof MochiKit.Async.CancelledError)) {
188 result = confirmationDialog.deferredError({
189 'type': 'ALERT',
190 'title':"Error",
191 'text': Clipperz.PM.Strings.errorDescriptionForException(anError),
192 'buttons':[{text:"Close", result:'CANCEL', isDefault:true}]
193 })
194 } else {
195 result = anError;
196 }
197
198 return result;
199 });
200 deferredResult.callback();
201
202 return deferredResult;
203 },
204
205 //=============================================================================
206 __syntaxFix__: "syntax fix"
207});