5 new, 10 updated patches.
[webos-internals:justyns-modifications.git] / email / email-notification-repeat.patch
1 diff --git a/usr/palm/applications/com.palm.app.email/app/controllers/accountmanager-assistant.js b/usr/palm/applications/com.palm.app.email/app/controllers/accountmanager-assistant.js
2 index 6cf2b34..7b536dc 100644
3 --- a/usr/palm/applications/com.palm.app.email/app/controllers/accountmanager-assistant.js
4 +++ b/usr/palm/applications/com.palm.app.email/app/controllers/accountmanager-assistant.js
5 @@ -9,6 +9,13 @@ var AccountmanagerAssistant = Class.create({
6         },
7  
8         activate: function() {
9 +               
10 +               //repeat notification handlers
11 +               this.notificationRepeatIntervalClickHandler = this.handleNotificationRepeatIntervalClick.bindAsEventListener(this);
12 +               this.controller.get('pv_notification_repeat_interval').observe('mojo-tap', this.notificationRepeatIntervalClickHandler);
13 +               this.notificationMaxRepeatClickHandler = this.handleNotificationMaxRepeatClick.bindAsEventListener(this);
14 +               this.controller.get('pv_notification_max_repeat').observe('mojo-tap', this.notificationMaxRepeatClickHandler);
15 +               
16                 this.delayActivate = false;
17                 // Clear the notification filters so user will get notified when any email comes in
18                 var notificationAssistant = Mojo.Controller.getAppController().assistant.notificationAssistant;
19 @@ -24,6 +31,15 @@ var AccountmanagerAssistant = Class.create({
20                 }
21         },
22  
23 +       deactivate: function() {
24 +               
25 +               //stop observing notification repeat controls
26 +               this.controller.get('pv_notification_repeat_interval').stopObserving('mojo-tap', this.notificationRepeatIntervalClickHandler);
27 +               this.notificationRepeatIntervalClickHandler = undefined;
28 +               this.controller.get('pv_notification_max_repeat').stopObserving('mojo-tap', this.notificationMaxRepeatClickHandler);
29 +               this.notificationMaxRepeatClickHandler = undefined;
30 +       },
31 +               
32         aboutToActivate: function(callback) {
33                 if (this.delayActivate === true) {
34                         this.readyToActivateCallback = callback;
35 @@ -37,6 +53,40 @@ var AccountmanagerAssistant = Class.create({
36         },
37  
38         setup: function() {
39 +       
40 +               //get notification repeat interval and max repeat values from cookie
41 +               this.notificationCookie = new Mojo.Model.Cookie("com.palm.app.email.notificationrepeat");
42 +
43 +               if (this.notificationCookie) 
44 +               {
45 +                       var notificationCookie = this.notificationCookie.get();
46 +
47 +                       if (notificationCookie) 
48 +                       {                       
49 +                               if(notificationCookie.notificationRepeatInterval)
50 +                               {
51 +                                       this.notificationRepeatInterval = notificationCookie.notificationRepeatInterval;
52 +                               }
53 +                               else
54 +                               {
55 +                                       //set default value to 2 minutes
56 +                                       this.notificationRepeatInterval = '2';
57 +                               }
58 +                               
59 +                               if(notificationCookie.notificationMaxRepeat)
60 +                               {
61 +                                       this.notificationMaxRepeat = notificationCookie.notificationMaxRepeat;
62 +                               }
63 +                               else
64 +                               {
65 +                                       //set default value to unlimited
66 +                                       this.notificationMaxRepeat = '99999';
67 +                               }
68 +                       }
69 +               }
70 +               
71 +               this.renderNotificationRepeatValues(this.getCurrentNotificationRepeatIntervalString(), this.getCurrentNotificationMaxRepeatString());
72 +               
73                 this.delayActivate = true;
74                 this.accountsListElement = this.controller.get('accounts_list');
75                 this.defaultAccountElement = this.controller.get('account-manager-default-account');
76 @@ -148,6 +198,16 @@ var AccountmanagerAssistant = Class.create({
77         },
78  
79         cleanup: function() {
80 +               
81 +               //save notification repeat preferences
82 +               if (this.notificationCookie)
83 +               {
84 +                       this.notificationCookie.put({
85 +                                                                               notificationRepeatInterval: this.notificationRepeatInterval,
86 +                                                                               notificationMaxRepeat: this.notificationMaxRepeat
87 +                                                                               });
88 +               }
89 +               
90                 this.accountsRequest.cancel();
91                 this.accountsRequest = null;
92                 this.accountsListElement = "";
93 @@ -347,7 +407,122 @@ var AccountmanagerAssistant = Class.create({
94                 } else {
95                         Mojo.Log.error("This Is Bad: accountmanager cannot maintain accountList subscription after 3 retries " + $H(err).inspect());
96                 }
97 -       }
98 +       },
99 +       
100 +       //notification repat settings section
101 +       renderNotificationRepeatValues: function(notificationRepeatIntervalStr, notificationMaxRepeatStr) {
102 +               //Mojo.Log.info('prefs-assistant: renderNotificationRepeatValues');
103 +               var obj = {};
104 +               
105 +               // Notification Repeat Interval
106 +               this.controller.get('pv_notification_repeat_interval_value').update(notificationRepeatIntervalStr);
107 +               
108 +               // Notification Max Repeat
109 +               this.controller.get('pv_notification_max_repeat_value').update(notificationMaxRepeatStr);
110 +       },
111 +       
112 +       getCurrentNotificationRepeatIntervalString: function() {
113 +               var index = 0;
114 +               for (index = 0; index < this.notificationRepeatIntervals.size(); index++) {
115 +                       if (this.notificationRepeatIntervals[index].command == this.notificationRepeatInterval)
116 +                               return this.notificationRepeatIntervals[index].label;
117 +               }
118 +       },
119 +       
120 +       getCurrentNotificationMaxRepeatString: function() {
121 +               var index = 0;
122 +               for (index = 0; index < this.notificationMaxRepeats.size(); index++) {
123 +                       if (this.notificationMaxRepeats[index].command == this.notificationMaxRepeat)
124 +                               return this.notificationMaxRepeats[index].label;
125 +               }
126 +       },
127 +       
128 +       notificationRepeatIntervalChoose: function(value) {
129 +               //Mojo.Log.info('prefs-assistant: defaultNotificationRepeatIntervalChoose');
130 +               
131 +               if (value != undefined && value != this.notificationRepeatInterval) {
132 +                       this.notificationRepeatInterval = value;
133 +                       this.renderNotificationRepeatValues(this.getCurrentNotificationRepeatIntervalString(), this.getCurrentNotificationMaxRepeatString());
134 +                       this.dirty = true;
135 +               }
136 +       },
137 +       
138 +       handleNotificationRepeatIntervalClick: function(event) {
139 +               //Mojo.Log.info('prefs-assistant: handleNotificationRepeatIntervalClick');
140 +
141 +               Event.stop(event);
142 +               this.controller.popupSubmenu({
143 +                               onChoose: this.notificationRepeatIntervalChoose.bind(this),
144 +                               toggleCmd: this.notificationRepeatInterval,
145 +                               items: this.notificationRepeatIntervals
146 +                       });
147 +       },
148 +       
149 +       notificationMaxRepeatChoose: function(value) {
150 +               //Mojo.Log.info('prefs-assistant: notificationMaxRepeatChoose');
151 +               
152 +               if (value != undefined && value != this.notificationMaxRepeat) {
153 +                       this.notificationMaxRepeat = value;
154 +                       this.renderNotificationRepeatValues(this.getCurrentNotificationRepeatIntervalString(), this.getCurrentNotificationMaxRepeatString());
155 +                       this.dirty = true;
156 +               }
157 +       },
158 +       
159 +       handleNotificationMaxRepeatClick: function(event) {
160 +               //Mojo.Log.info('prefs-assistant: handleNotificationMaxRepeatClick');
161 +
162 +               Event.stop(event);
163 +               this.controller.popupSubmenu({
164 +                               onChoose: this.notificationMaxRepeatChoose.bind(this),
165 +                               toggleCmd: this.notificationMaxRepeat,
166 +                               items: this.notificationMaxRepeats
167 +                       });
168 +       },
169 +       
170 +       notificationRepeatIntervals: [
171 +               {label:$L('Disabled'), command:'0'},
172 +               {label:$L('5 Seconds'), command:'.083'},
173 +               {label:$L('10 Seconds'), command:'.167'},
174 +               {label:$L('15 Seconds'), command:'.25'},
175 +               {label:$L('20 Seconds'), command:'.333'},
176 +               {label:$L('25 Seconds'), command:'.417'},
177 +               {label:$L('30 Seconds'), command:'.5'},
178 +               {label:$L('1 Minutes'), command:'1'},
179 +               {label:$L('2 Minutes'), command:'2'},
180 +               {label:$L('3 Minutes'), command:'3'},
181 +               {label:$L('4 Minutes'), command:'4'},
182 +               {label:$L('5 Minutes'), command:'5'},
183 +               {label:$L('10 Minutes'), command:'10'},
184 +               {label:$L('15 Minutes'), command:'15'}
185 +       ],
186 +       
187 +       notificationMaxRepeats: [
188 +               {label:$L('Unlimited'), command:'99999'}, //this should be a large enough value to be conisdered unlimited for our purpose.
189 +               {label:$L('1'), command:'1'},
190 +               {label:$L('2'), command:'2'},
191 +               {label:$L('3'), command:'3'},
192 +               {label:$L('4'), command:'4'},
193 +               {label:$L('5'), command:'5'},
194 +               {label:$L('10'), command:'10'},
195 +               {label:$L('15'), command:'15'},
196 +               {label:$L('20'), command:'20'},
197 +               {label:$L('25'), command:'25'},
198 +               {label:$L('30'), command:'30'},
199 +               {label:$L('35'), command:'35'},
200 +               {label:$L('40'), command:'40'},
201 +               {label:$L('45'), command:'45'},
202 +               {label:$L('50'), command:'50'},
203 +               {label:$L('55'), command:'55'},
204 +               {label:$L('60'), command:'60'},
205 +               {label:$L('65'), command:'65'},
206 +               {label:$L('70'), command:'70'},
207 +               {label:$L('75'), command:'75'},
208 +               {label:$L('80'), command:'80'},
209 +               {label:$L('85'), command:'85'},
210 +               {label:$L('90'), command:'90'},
211 +               {label:$L('95'), command:'95'},
212 +               {label:$L('100'), command:'100'}
213 +       ]
214  
215  });
216  
217 diff --git a/usr/palm/applications/com.palm.app.email/app/controllers/app-assistant.js b/usr/palm/applications/com.palm.app.email/app/controllers/app-assistant.js
218 index 5704019..e0b03a8 100644
219 --- a/usr/palm/applications/com.palm.app.email/app/controllers/app-assistant.js
220 +++ b/usr/palm/applications/com.palm.app.email/app/controllers/app-assistant.js
221 @@ -128,11 +128,40 @@ LaunchHandler = Class.create({
222                         this.handleContact(params);
223                 } else if (params.carrierSignature) {
224                         this.handleSetCarrierSignature(params);
225 +               } else if(params.playalarmsound){
226 +                       this.playAlarmSound();
227                 } else {
228                         this.handleDefault();
229                 }
230         },
231         
232 +       playAlarmSound: function() {
233 +               try
234 +               {
235 +                       var dashboard = null;
236 +                       
237 +                       if (this.allInboxesOn) 
238 +                       {
239 +                               dashboard = this.notificationAssistant.appController.getStageProxy(NotificationAssistant.kNewEmailDashboardStageName);
240 +                       }
241 +                       else
242 +                       {
243 +                               //get a valid stage name by using the first element of the notificaitons array
244 +                               if( this.notificationAssistant.notificationInfo.length )
245 +                               {
246 +                                       dashboard = this.notificationAssistant.appController.getStageProxy(NotificationAssistant.kNewEmailDashboardStageName + this.notificationAssistant.notificationInfo[0].account);
247 +                               }
248 +                       }
249 +               
250 +                       if (dashboard) {
251 +                               dashboard.delegateToSceneAssistant("playAlarmSound");
252 +                       }
253 +               }
254 +               catch (e) {
255 +                       Mojo.Log.logException(e, "app-assistant-playAlarmSound");
256 +               }
257 +       },
258 +       
259         handleCompose: function() {
260                 var params = this.launchParameters;
261                 var email = new Email();
262 diff --git a/usr/palm/applications/com.palm.app.email/app/controllers/email-dashboard-assistant.js b/usr/palm/applications/com.palm.app.email/app/controllers/email-dashboard-assistant.js
263 index e8278ac..cbd1984 100644
264 --- a/usr/palm/applications/com.palm.app.email/app/controllers/email-dashboard-assistant.js
265 +++ b/usr/palm/applications/com.palm.app.email/app/controllers/email-dashboard-assistant.js
266 @@ -4,15 +4,54 @@ Copyright 2009 Palm, Inc.  All rights reserved.
267  
268  */
269  
270 +g_notificationRepeatCount = 0;
271 +
272  var EmailDashboardAssistant = Class.create({
273         
274         initialize: function(notificationAssistant, notifications) {
275                 this.notificationAssistant = notificationAssistant;
276                 this.notifications = notifications;
277                 this.allInboxesOn = this.notificationAssistant.allInboxesOn;
278 +
279 +               //need to access the details for what is being displayed so we can get the folder obj
280 +               //to access the sound that should be played
281 +               this.itemDetails = undefined;
282         },
283  
284         setup: function() {
285 +       
286 +               //load the notification repeat preferences.
287 +               //get notification repeat interval and max repeat values from cookie
288 +               this.notificationCookie = new Mojo.Model.Cookie("com.palm.app.email.notificationrepeat");
289 +               
290 +               if (this.notificationCookie) 
291 +               {
292 +                       var notificationCookie = this.notificationCookie.get();
293 +
294 +                       if (notificationCookie) 
295 +                       {                       
296 +                               if(notificationCookie.notificationRepeatInterval)
297 +                               {
298 +                                       this.notificationRepeatInterval = notificationCookie.notificationRepeatInterval;
299 +                               }
300 +                               else
301 +                               {
302 +                                       //set default value to 2 minutes
303 +                                       this.notificationRepeatInterval = '2';
304 +                               }
305 +                               
306 +                               if(notificationCookie.notificationMaxRepeat)
307 +                               {
308 +                                       this.notificationMaxRepeat = notificationCookie.notificationMaxRepeat;
309 +                               }
310 +                               else
311 +                               {
312 +                                       //set default value to unlimited
313 +                                       this.notificationMaxRepeat = '99999';
314 +                               }
315 +                       }
316 +               }
317 +               
318                 this.update(this.notifications);
319                 this.boundTapHandler = this.tapHandler.bindAsEventListener(this);
320                 this.controller.sceneElement.observe(Mojo.Event.tap, this.boundTapHandler);
321 @@ -41,6 +80,9 @@ var EmailDashboardAssistant = Class.create({
322                 // turn off throbber
323                 Mojo.Log.info('Turning off throbber');
324                 this.controller.stageController.indicateNewContent(false);
325 +
326 +               //remove the Notification repeat task
327 +               this.removePlayAlarmSoundTask();
328         },
329  
330         tapHandler: function(event) {
331 @@ -71,17 +113,20 @@ var EmailDashboardAssistant = Class.create({
332         },
333  
334         update: function(notificationInfo) {
335 +               //remove the nag reminder
336 +               this.removePlayAlarmSoundTask();
337 +
338                 if (!this.notificationAssistant) {
339                         Mojo.Log.error("I feel a disturbance in the Force... As if notificationAssistant isn't there");
340                         return;
341                 }
342  
343 +               //reschedule the nag reminder
344 +               this.schedulePlayAlarmSoundTask();
345 +
346                 var content;
347                 var latestDetails;
348  
349 -               // turn on throbber
350 -               Mojo.Log.info('Turning on throbber for new email notification');
351 -               this.controller.stageController.indicateNewContent(true);
352                 
353                 // update notifications if they are changed.
354                 this.notifications = notificationInfo;
355 @@ -125,6 +170,9 @@ var EmailDashboardAssistant = Class.create({
356                 }
357         
358                 this.controller.sceneElement.update(content);
359 +
360 +               //set item details to support nag reminder
361 +               this.itemDetails = latestDetails;
362         },
363         
364         getEscapedNotification: function(folderObj) {
365 @@ -219,4 +267,72 @@ var EmailDashboardAssistant = Class.create({
366                 this.allInboxesOn = params.allInboxesOn;
367         },
368  
369 +       playAlarmSound: function() {
370 +
371 +               var playSoundParams = [];
372 +               
373 +               //play nag sound and reschedule
374 +               if (this.itemDetails)
375 +               {
376 +                       if (this.itemDetails.playSound !== AccountpreferencesAssistant.kNotifyTypeNone) {
377 +
378 +                               var soundParams = this.notificationAssistant.getSoundNotificationClass(this.itemDetails);
379 +                               if( soundParams )
380 +                               {
381 +                                       playSoundParams.push(soundParams);
382 +                               }
383 +                               
384 +                               if (playSoundParams.length > 0) {
385 +                                       this.notificationAssistant.playNotificationSounds(playSoundParams);
386 +                               }
387 +
388 +                               this.schedulePlayAlarmSoundTask();
389 +                       }
390 +               }
391 +       },
392 +
393 +       schedulePlayAlarmSoundTask: function() {
394 +               try {
395 +               
396 +                       //retrigger reminder every X minutes until we acknowledge it.
397 +                       //notificationRepeatInterval disables the notification repeat
398 +                       //also check to make sure we have not exceeded the max repeat value
399 +                       if( parseFloat(this.notificationRepeatInterval) != 0 && g_notificationRepeatCount < parseInt(this.notificationMaxRepeat))
400 +                       {
401 +                               g_notificationRepeatCount++;
402 +
403 +                               var playSoundTime = new Date();
404 +                               playSoundTime = new Date(playSoundTime.getTime() + parseFloat(this.notificationRepeatInterval)*60*1000);
405 +
406 +                               this.controller.serviceRequest('palm://com.palm.taskScheduler', {
407 +                                       method: 'updateTask',
408 +                                       parameters: {uri: 'palm://com.palm.applicationManager/open',
409 +                                       arguments: {'id': 'com.palm.app.email',
410 +                                               'params': {'playalarmsound': true}},
411 +                                       key: 'email-playalarmsound',
412 +                                       start: {date: playSoundTime.toUTCString()}}
413 +                                       });
414 +                       }
415 +               }
416 +               catch (e) {
417 +                       Mojo.Log.logException(e, "email-dashboard-assistant.schedulePlayAlarmSoundTask");
418 +               }
419 +       },
420 +
421 +       removePlayAlarmSoundTask: function() {
422 +               try 
423 +               {
424 +                       //reset the notification repeat counter
425 +                       g_notificationRepeatCount = 0;
426 +               
427 +                       this.controller.serviceRequest('palm://com.palm.taskScheduler', {
428 +                               method: 'removeTask',
429 +                               parameters: {key: 'email-playalarmsound'}
430 +                               });
431 +               }
432 +               catch (e) {
433 +                       //Mojo.Log.logException(e, "email-dashboard-assistant.removePlayAlarmSoundTask");
434 +               }
435 +       },
436 +
437  });
438 diff --git a/usr/palm/applications/com.palm.app.email/app/views/accountmanager/accountmanager-scene.html b/usr/palm/applications/com.palm.app.email/app/views/accountmanager/accountmanager-scene.html
439 index f08657e..c980344 100644
440 --- a/usr/palm/applications/com.palm.app.email/app/views/accountmanager/accountmanager-scene.html
441 +++ b/usr/palm/applications/com.palm.app.email/app/views/accountmanager/accountmanager-scene.html
442 @@ -8,6 +8,25 @@
443                 </div>                                                                                                                                                                         
444         </div>
445  
446 +       <div id='pv_notificationrepeat_div' class="palm-group">
447 +               <div class="palm-group-title" x-mojo-loc="">Notification Repeat</div>
448 +               <div class="palm-list">
449 +                       <div id="pv_notification_repeat_interval" class="palm-row">
450 +                               <div class="palm-row-wrapper">
451 +                                       <div class="label" x-mojo-loc="">Repeat Interval</div>
452 +                                       <div id="pv_notification_repeat_interval_value" class="title"></div>
453 +                               </div>
454 +                       </div>
455 +                       
456 +                       <div id="pv_notification_max_repeat" class="palm-row">
457 +                               <div class="palm-row-wrapper">
458 +                                       <div class="label" x-mojo-loc="">Max Repeats</div>
459 +                                       <div id="pv_notification_max_repeat_value" class="title"></div>
460 +                               </div>
461 +                       </div>
462 +               </div>
463 +       </div>
464 +       
465         <div class="palm-group">
466                 <div class="palm-group-title" x-mojo-loc=''>Smart Folders</div>
467                 <div class="palm-list">