summaryrefslogtreecommitdiff
path: root/frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/CardList.js
Unidiff
Diffstat (limited to 'frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/CardList.js') (more/less context) (ignore whitespace changes)
-rw-r--r--frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/CardList.js254
1 files changed, 254 insertions, 0 deletions
diff --git a/frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/CardList.js b/frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/CardList.js
new file mode 100644
index 0000000..a4aa212
--- a/dev/null
+++ b/frontend/gamma/js/Clipperz/PM/UI/Mobile/Components/CardList.js
@@ -0,0 +1,254 @@
1/*
2
3Copyright 2008-2011 Clipperz Srl
4
5This file is part of Clipperz Community Edition.
6Clipperz Community Edition is an online password manager.
7For further information about its features and functionalities please
8refer to http://www.clipperz.com.
9
10* Clipperz Community Edition is free software: you can redistribute
11 it and/or modify it under the terms of the GNU Affero General Public
12 License as published by the Free Software Foundation, either version
13 3 of the License, or (at your option) any later version.
14
15* Clipperz Community Edition is distributed in the hope that it will
16 be useful, but WITHOUT ANY WARRANTY; without even the implied
17 warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU Affero General Public License for more details.
19
20* You should have received a copy of the GNU Affero General Public
21 License along with Clipperz Community Edition. If not, see
22 <http://www.gnu.org/licenses/>.
23
24*/
25
26Clipperz.Base.module('Clipperz.PM.UI.Mobile.Components');
27
28Clipperz.PM.UI.Mobile.Components.CardList = function(args) {
29 args = args || {};
30
31 Clipperz.PM.UI.Mobile.Components.CardList.superclass.constructor.apply(this, arguments);
32
33 this._cardDetail = null;
34
35 return this;
36}
37
38//=============================================================================
39
40Clipperz.Base.extend(Clipperz.PM.UI.Mobile.Components.CardList, Clipperz.PM.UI.Common.Components.BaseComponent, {
41
42 //-------------------------------------------------------------------------
43
44 'toString': function () {
45 return "Clipperz.PM.UI.Mobile.Components.CardList component";
46 },
47
48 //-------------------------------------------------------------------------
49
50 'renderSelf': function () {
51 this.append(this.element(), {tag:'div', cls:'cardList', children:[
52 {tag:'div', cls:'toolbar', children:[
53 {tag:'h1', html:"clipperz"},
54 // {tag:'input', name:'search', type:'search', autocomplete:'off', placeholder:"search", id:this.getId('search')},
55 {tag:'a', href:'#', id:'settings', cls:'button', html:"*"}
56 ]},
57 {tag:'div', cls:'scroll', id:this.getId('listBox'), children:[
58 {tag:'ul', cls:'rounded', id:this.getId('list'), children:[
59 {tag:'li', html:'loading'}
60 ]}
61 ]}
62 ]});
63
64 MochiKit.Signal.connect(this.getElement('list'), 'onclick', this, 'cardSelectionHandler');
65 MochiKit.Signal.connect(this.getElement('list'), 'ontouchstart',this, 'cardSelectionHandler');
66 // MochiKit.Signal.connect(this.getElement('cardListSearchForm'), 'onsubmit', this,'searchHandler');
67 // MochiKit.Signal.connect(this.getElement('cardListSearchForm'), 'onkeydown', this,'searchHandler');
68 // MochiKit.Signal.connect(this.getElement('cardListSearchForm'), 'onkeyup', this,'searchHandler');
69
70 // MochiKit.Signal.connect(this.getElement('cardListPanel'), 'onclick', this,'cardListClickHandler');
71 // MochiKit.Signal.connect('backButton', 'onclick', this,'backButtonClickHandler');
72
73 // MochiKit.Style.hideElement('backButton');
74 // MochiKit.Style.hideElement(this.getElement('cardDetail'));
75 },
76
77 'showCards': function (someCards) {
78 varcardListElement;
79 if (this.isFullyRendered() == false) {
80 this.render();
81 };
82
83 cardListElement = this.getElement('list')
84
85 cardInfo = {
86 '_rowObject': MochiKit.Async.succeed,
87 '_reference': MochiKit.Base.methodcaller('reference'),
88 '_searchableContent':MochiKit.Base.methodcaller('searchableContent'),
89 'label': MochiKit.Base.methodcaller('label'),
90 'favicon': MochiKit.Base.methodcaller('favicon')
91 };
92
93//console.log("someCards", someCards);
94 deferredResult = new Clipperz.Async.Deferred("CardList.showCards", {trace:false});
95 deferredResult.addCallback(MochiKit.Base.map, Clipperz.Async.collectResults("CardList.value - collectResults", cardInfo, {trace:false}));
96 deferredResult.addCallback(Clipperz.Async.collectAll);
97 deferredResult.addCallback(MochiKit.Base.methodcaller('sort', Clipperz.Base.caseInsensitiveKeyComparator('label')));
98 deferredResult.addCallbackPass(MochiKit.DOM.replaceChildNodes, cardListElement);
99 // deferredResult.addCallbackPass(MochiKit.DOM.removeElementClass, cardListElement, 'loading');
100 deferredResult.addCallback(MochiKit.Base.map, MochiKit.Base.method(this, 'appendCardToList', cardListElement));
101 deferredResult.callback(someCards);
102 },
103
104 'appendCardToList': function (aCardListElement, aCardInfo) {
105//console.log("appendCardToList", aCardInfo);
106 this.append(aCardListElement, {tag:'li', cls:'cardListItem arrow', cardreference:aCardInfo['_reference'], children:[
107 {tag:'a', href:'#', html:aCardInfo['label'], children:[
108 {tag:'small', cls:'favicon', children:[{tag:'img', cls:'favicon', src:aCardInfo['favicon']}]}
109 ]}
110 ]});
111 },
112
113 'cardSelectionHandler': function (anEvent) {
114 var listElement;
115 varcardReference;
116
117 anEvent.preventDefault();
118
119 listElement = anEvent.target();
120 if (MochiKit.DOM.getNodeAttribute(listElement, 'cardreference') == null) {
121 listElement = MochiKit.DOM.getFirstParentByTagAndClassName(anEvent.target(), tagName='li', className='cardListItem');
122 }
123 cardReference = MochiKit.DOM.getNodeAttribute(listElement, 'cardreference');
124console.log("###", listElement, cardReference);
125 //TODO: Notify card with reference MochiKit.DOM.getNodeAttribute(listElement, 'cardreference') has been selected
126 MochiKit.Signal.signal(this, 'selectedCard', cardReference);
127 },
128
129 //-------------------------------------------------------------------------
130/*
131 'searchHandler': function (anEvent) {
132 if ((typeof(anEvent.key()) != 'undefined') && (anEvent.key().string == 'KEY_ENTER')) { //RETURN
133 anEvent.preventDefault();
134 } else {
135 if ((typeof(anEvent.key()) != 'undefined') && (anEvent.key().string == 'KEY_ESCAPE')) {
136 anEvent.target().value = "";
137 }
138
139 if (anEvent.type() == 'keyup') {
140 MochiKit.Signal.signal(this, 'searchEvent', anEvent.target().value);
141 }
142 }
143 },
144
145 //-------------------------------------------------------------------------
146
147 'update': function (someObjects) {
148 varcardListPanel;
149 var i,c;
150
151 cardListPanel = this.getElement('cardListPanel');
152 cardListPanel.innerHTML = '';
153
154 c = someObjects.length;
155
156 for (i=0; i<c; i++) {
157 this.append(cardListPanel, {tag:'li', cls:'cardListItem', id:('cardListItem_' + someObjects[i]['_reference']), children:[
158 {tag:'img', src:(someObjects[i]['favicon'] ? someObjects[i]['favicon'] : 'data:application/octet-stream;charset=utf-8;base64,AAABAAEAFxcAAAEAGAD8BgAAFgAAACgAAAAXAAAALgAAAAEAGAAAAAAAAAAAABIXAAASFwAAAAAAAAAAAAD///////////////////////////////////////////////////////////////////////////////////////////9zAC////////////////////////////////////////////////////////////////////////////////////////////9pAG////////////////////////////////////////////////////////////////////////////////////////////9rAC////////////////////////////////////////////////////////////////////////////////////////////9yAHP////////////////////////IyMizs7O6urrq6ur////////////Ozs6zs7Ozs7Pq6ur///////////////////////8AAAD////////////////////V1dWXl5eXl5eXl5elpaX4+Pj////Ozs6Xl5eXl5eXl5eenp7///////////////////////8AAAD////////////////////Ozs6Xl5eXl5eXl5eXl5fBwcHq6uqenp6Xl5eXl5eXl5eXl5f///////////////////////8AAAD////////////////////j4+OXl5eXl5eXl5eXl5eXl5elpaWXl5eXl5eXl5eXl5ezs7P///////////////////////8AAAD////////////////////////IyMiXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eenp7x8fH////////////////////////////////////////////////////4+PilpaWXl5eXl5eXl5eXl5eXl5eXl5eXl5fOzs7////////////////////////////////////////////////////////q6uq6urqXl5eXl5eXl5eXl5eXl5eXl5eenp7V1dX4+Pj///////////////////////8AAAD////////////4+PjOzs6lpaWXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5e6urrj4+P///////////////8AAAD////////////BwcGXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5fx8fH///////////8AAAD///////////+zs7OXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5fj4+P///////////8AAAD////////////IyMiXl5eXl5eXl5eXl5e6urqXl5eXl5eXl5eXl5esrKylpaWXl5eXl5eXl5eenp7x8fH///////////8AAAD////////////////Ozs7Ozs7V1dX4+Pj///+Xl5eXl5eXl5eXl5fOzs7////q6urOzs7Ozs7q6ur///////////////8AAAD///////////////////////////////////+Xl5eXl5eXl5eXl5fOzs7///////////////////////////////////8AAAD///////////////////////////////////+Xl5eXl5eXl5eXl5fOzs7///////////////////////////////////8AAAD///////////////////////////////////+Xl5eXl5eXl5eXl5fOzs7///////////////////////////////////8AAAD////////////////////////////////////IyMiXl5eXl5eenp7x8fH///////////////////////////////////8AAAD////////////////////////////////////////j4+Pj4+Px8fH///////////////////////////////////////8AAAD///////////////////////////////////////////////////////////////////////////////////////////8AAAD///////////////////////////////////////////////////////////////////////////////////////////8AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAo=')},
159 {tag:'a', id:('cardListReference_' + someObjects[i]['_reference']), href:'#', html:someObjects[i]['label']}
160 ]})
161
162 MochiKit.Signal.connect('cardListItem_' + someObjects[i]['_reference'], 'onclick', this, 'cardListClickHandler');
163 }
164
165 },
166
167 'cardListClickHandler': function (anEvent) {
168 anEvent.preventDefault();
169
170 if (/(cardListReference_|cardListItem_)/.test(anEvent.target().id)) {
171 var cardListReference;
172
173 cardListReference = anEvent.target().id.match(/(cardListReference_|cardListItem_)(.*)/)[2];
174//console.log("Showing detail for card named", cardListReference);
175 MochiKit.Signal.signal(this, 'selectedCard', cardListReference);
176 }
177 },
178
179 //=========================================================================
180
181 'cardDetail': function (someData) {
182 if (this._cardDetail == null) {
183 this._cardDetail = new Clipperz.PM.UI.Mobile.Components.CardDetail({element:this.getElement('cardDetail')});
184 }
185
186 return this._cardDetail;
187 },
188
189 //-------------------------------------------------------------------------
190
191 'removeCardDetail': function () {
192 if (this._cardDetail != null) {
193 this._cardDetail.remove();
194 this._cardDetail = null;
195 }
196 },
197
198 //=========================================================================
199
200 'showCard': function (someData) {
201 vardeferredResult;
202 varoffset;
203
204 offset = ((MochiKit.DOM.getNodeAttribute(MochiKit.DOM.currentDocument().body, 'orientation') == 'portrait') ? 320 : 480);
205 this.cardDetail().render();
206 this.cardDetail().setCardReference(someData['_reference']);
207 MochiKit.Style.setElementPosition(this.cardDetail().element(), {x:offset});
208 new MochiKit.Visual.Sequence([
209 // new MochiKit.Visual.Move(this.cardDetail().element(), {x:offset, y:45, mode:'absolute', duration:0, sync:true}),
210 new MochiKit.Visual.Parallel([
211 new MochiKit.Visual.Move(this.getElement('cardList'), {x:-offset, y:0, mode:'relative',transition:MochiKit.Visual.Transitions.linear, sync:true}),
212 new MochiKit.Visual.Move(this.getElement('cardDetail'), {x:0, y:45, mode:'absolute',transition:MochiKit.Visual.Transitions.linear, sync:true}),
213 // new MochiKit.Visual.ScrollTo('toolbar', {sync:true}),
214 MochiKit.Visual.appear ('backButton', { transition:MochiKit.Visual.Transitions.linear, sync:true})
215 ], {duration:1, sync:true}),
216 MochiKit.Visual.fade(this.getElement('cardList'), {duration:0, sync:true})
217 ], {})
218
219 MochiKit.DOM.getElement('pageTitle').innerHTML = someData['title'];
220
221 return true;
222 },
223
224 //-------------------------------------------------------------------------
225
226 'showCardDetails': function (someData) {
227 return this.cardDetail().showCardDetails(someData);
228 },
229
230 //=========================================================================
231
232 'backButtonClickHandler': function (anEvent) {
233 varoffset;
234
235 anEvent.preventDefault();
236
237 MochiKit.DOM.getElement('pageTitle').innerHTML = "cards";
238
239 offset = ((MochiKit.DOM.getNodeAttribute(MochiKit.DOM.currentDocument().body, 'orientation') == 'portrait') ? 320 : 480);
240 MochiKit.Style.setElementPosition(this.getElement('cardList'), {x:-offset});
241 MochiKit.DOM.showElement(this.getElement('cardList'));
242
243 new MochiKit.Visual.Parallel([
244 new MochiKit.Visual.Move(this.getElement('cardList'), {x:offset, y:0, mode:'relative',transition:MochiKit.Visual.Transitions.linear, sync:true}),
245 new MochiKit.Visual.Move(this.getElement('cardDetail'), {x:offset, y:0, mode:'relative',transition:MochiKit.Visual.Transitions.linear, sync:true}),
246 MochiKit.Visual.fade (this.getElement('cardDetail'), { transition:MochiKit.Visual.Transitions.linear, sync:true}),
247 MochiKit.Visual.fade ('backButton', { transition:MochiKit.Visual.Transitions.linear, sync:true})
248 ], {duration:1, afterFinish:MochiKit.Base.method(this, 'removeCardDetail')})
249
250 },
251*/
252 //=========================================================================
253 __syntaxFix__: "syntax fix"
254});