5 new, 10 updated patches.
[webos-internals:djcin7s-modifications.git] / calendar / calendar-notification-repeat.patch
1 diff --git a/usr/palm/applications/com.palm.app.calendar/app/controllers/app-assistant.js b/usr/palm/applications/com.palm.app.calendar/app/controllers/app-assistant.js
2 index 5375929..a6d18b0 100644
3 --- a/usr/palm/applications/com.palm.app.calendar/app/controllers/app-assistant.js
4 +++ b/usr/palm/applications/com.palm.app.calendar/app/controllers/app-assistant.js
5 @@ -117,6 +117,9 @@ var AppAssistant = Class.create({
6                         Mojo.Log.info("$$$$$$$$ AppAssistant handleLaunch : alarmclose");
7                         this.closeReminder(launchParams.alarmclose);
8                 } 
9 +               else if (launchParams.playalarmsound){
10 +                       this.playAlarmSound();
11 +               }
12                 else if (launchParams.dayChange){
13                         this.dayChange();
14                 }
15 @@ -267,6 +270,13 @@ var AppAssistant = Class.create({
16                 Mojo.Log.info("$$$$$$$$ AppAssistant closeReminder:end");
17         },
18         
19 +       playAlarmSound: function() {
20 +               if (this.openReminderAlert) {
21 +                       this.openReminderAlert.playAlarmSound();
22 +                       this.openReminderAlert = null;
23 +               }
24 +       },
25 +
26         scheduleNextReminder: function(eventId) {
27                 Mojo.Log.info("$$$$$$$$ AppAssistant scheduleNextReminder: for event:"+eventId);
28                 new Mojo.Service.Request('palm://com.palm.calendar', {
29 diff --git a/usr/palm/applications/com.palm.app.calendar/app/controllers/prefs-assistant.js b/usr/palm/applications/com.palm.app.calendar/app/controllers/prefs-assistant.js
30 index cebe803..5370044 100644
31 --- a/usr/palm/applications/com.palm.app.calendar/app/controllers/prefs-assistant.js
32 +++ b/usr/palm/applications/com.palm.app.calendar/app/controllers/prefs-assistant.js
33 @@ -179,6 +179,33 @@ var PrefsAssistant = Class.create({
34                 this.controller.get('pv_default_allday_evt_alarm_value').update(allDayAlarmStr);
35         },
36         
37 +       renderNotificationRepeatValues: function(notificationRepeatIntervalStr, notificationMaxRepeatStr) {
38 +               //Mojo.Log.info('prefs-assistant: renderNotificationRepeatValues');
39 +               var obj = {};
40 +               
41 +               // Notification Repeat Interval
42 +               this.controller.get('pv_notification_repeat_interval_value').update(notificationRepeatIntervalStr);
43 +               
44 +               // Notification Max Repeat
45 +               this.controller.get('pv_notification_max_repeat_value').update(notificationMaxRepeatStr);
46 +       },
47 +       
48 +       getCurrentNotificationRepeatIntervalString: function() {
49 +               var index = 0;
50 +               for (index = 0; index < this.notificationRepeatIntervals.size(); index++) {
51 +                       if (this.notificationRepeatIntervals[index].command == this.notificationRepeatInterval)
52 +                               return this.notificationRepeatIntervals[index].label;
53 +               }
54 +       },
55 +       
56 +       getCurrentNotificationMaxRepeatString: function() {
57 +               var index = 0;
58 +               for (index = 0; index < this.notificationMaxRepeats.size(); index++) {
59 +                       if (this.notificationMaxRepeats[index].command == this.notificationMaxRepeat)
60 +                               return this.notificationMaxRepeats[index].label;
61 +               }
62 +       },
63 +       
64         getCurrentAlarmString: function() {
65                 var index = 0;
66                 for (index = 0; index < this.alarms.size(); index++) {
67 @@ -375,6 +402,40 @@ var PrefsAssistant = Class.create({
68         },
69         
70         setup: function() {
71 +               
72 +               //get notification repeat interval and max repeat values from cookie
73 +               this.notificationCookie = new Mojo.Model.Cookie("com.palm.app.calendar.notificationrepeat");
74 +
75 +               if (this.notificationCookie) 
76 +               {
77 +                       var notificationCookie = this.notificationCookie.get();
78 +
79 +                       if (notificationCookie) 
80 +                       {                       
81 +                               if(notificationCookie.notificationRepeatInterval)
82 +                               {
83 +                                       this.notificationRepeatInterval = notificationCookie.notificationRepeatInterval;
84 +                               }
85 +                               else
86 +                               {
87 +                                       //set default value to 2 minutes
88 +                                       this.notificationRepeatInterval = '2';
89 +                               }
90 +                               
91 +                               if(notificationCookie.notificationMaxRepeat)
92 +                               {
93 +                                       this.notificationMaxRepeat = notificationCookie.notificationMaxRepeat;
94 +                               }
95 +                               else
96 +                               {
97 +                                       //set default value to unlimited
98 +                                       this.notificationMaxRepeat = '99999';
99 +                               }
100 +                       }
101 +               }
102 +               
103 +               this.renderNotificationRepeatValues(this.getCurrentNotificationRepeatIntervalString(), this.getCurrentNotificationMaxRepeatString());
104 +               
105                 // Retrieve the prefs from the service
106                 this.prefs = getPrefs();
107                 this.requests = [];
108 @@ -468,6 +529,16 @@ var PrefsAssistant = Class.create({
109         
110         cleanup: function() {
111                 //Mojo.Log.info("prefs-assistant:cleanup");
112 +
113 +               //save notification repeat preferences
114 +               if (this.notificationCookie)
115 +               {
116 +                       this.notificationCookie.put({
117 +                                                                               notificationRepeatInterval: this.notificationRepeatInterval,
118 +                                                                               notificationMaxRepeat: this.notificationMaxRepeat
119 +                                                                               });
120 +               }
121 +               
122                 getCalendarsManager().stopObservingCalendars('prefs');
123                 getPrefsManager().stopObservingCalendarPrefs('prefs');
124                 
125 @@ -497,6 +568,12 @@ var PrefsAssistant = Class.create({
126                 //Mojo.Log.info('prefs-assistant: activate');
127                 getPrefsManager().validateDefaultCalPref();
128                 
129 +               //repeat notification handlers
130 +               this.notificationRepeatIntervalClickHandler = this.handleNotificationRepeatIntervalClick.bindAsEventListener(this);
131 +               this.controller.get('pv_notification_repeat_interval').observe('mojo-tap', this.notificationRepeatIntervalClickHandler);
132 +               this.notificationMaxRepeatClickHandler = this.handleNotificationMaxRepeatClick.bindAsEventListener(this);
133 +               this.controller.get('pv_notification_max_repeat').observe('mojo-tap', this.notificationMaxRepeatClickHandler);
134 +               
135                 this.startOfWeekClickHandler = this.handleStartOfWeekClick.bindAsEventListener(this);
136                 this.controller.get('pv_start_of_week').observe('mojo-tap', this.startOfWeekClickHandler);
137                 
138 @@ -539,6 +616,13 @@ var PrefsAssistant = Class.create({
139         
140         deactivate: function() {
141                 //Mojo.Log.info('prefs-assistant: deactivate');
142 +               
143 +               //stop observing notification repeat controls
144 +               this.controller.get('pv_notification_repeat_interval').stopObserving('mojo-tap', this.notificationRepeatIntervalClickHandler);
145 +               this.notificationRepeatIntervalClickHandler = undefined;
146 +               this.controller.get('pv_notification_max_repeat').stopObserving('mojo-tap', this.notificationMaxRepeatClickHandler);
147 +               this.notificationMaxRepeatClickHandler = undefined;
148 +               
149                 this.controller.get('pv_start_of_week').stopObserving('mojo-tap', this.startOfWeekClickHandler);
150                 
151                 this.controller.get('pv_default_evt_alarm').stopObserving('mojo-tap', this.defaultEventAlarmClickHandler);
152 @@ -565,6 +649,48 @@ var PrefsAssistant = Class.create({
153         },
154         
155         // *** EVENT HANDLERS ***
156 +
157 +       notificationRepeatIntervalChoose: function(value) {
158 +               //Mojo.Log.info('prefs-assistant: defaultNotificationRepeatIntervalChoose');
159 +               
160 +               if (value != undefined && value != this.notificationRepeatInterval) {
161 +                       this.notificationRepeatInterval = value;
162 +                       this.renderNotificationRepeatValues(this.getCurrentNotificationRepeatIntervalString(), this.getCurrentNotificationMaxRepeatString());
163 +                       this.dirty = true;
164 +               }
165 +       },
166 +       
167 +       handleNotificationRepeatIntervalClick: function(event) {
168 +               //Mojo.Log.info('prefs-assistant: handleNotificationRepeatIntervalClick');
169 +
170 +               Event.stop(event);
171 +               this.controller.popupSubmenu({
172 +                               onChoose: this.notificationRepeatIntervalChoose.bind(this),
173 +                               toggleCmd: this.notificationRepeatInterval,
174 +                               items: this.notificationRepeatIntervals
175 +                       });
176 +       },
177 +       
178 +       notificationMaxRepeatChoose: function(value) {
179 +               //Mojo.Log.info('prefs-assistant: notificationMaxRepeatChoose');
180 +               
181 +               if (value != undefined && value != this.notificationMaxRepeat) {
182 +                       this.notificationMaxRepeat = value;
183 +                       this.renderNotificationRepeatValues(this.getCurrentNotificationRepeatIntervalString(), this.getCurrentNotificationMaxRepeatString());
184 +                       this.dirty = true;
185 +               }
186 +       },
187 +       
188 +       handleNotificationMaxRepeatClick: function(event) {
189 +               //Mojo.Log.info('prefs-assistant: handleNotificationMaxRepeatClick');
190 +
191 +               Event.stop(event);
192 +               this.controller.popupSubmenu({
193 +                               onChoose: this.notificationMaxRepeatChoose.bind(this),
194 +                               toggleCmd: this.notificationMaxRepeat,
195 +                               items: this.notificationMaxRepeats
196 +                       });
197 +       },
198         
199         handleDefaultCalClick: function(event) {
200                 //Mojo.Log.info("prefs-assistant: handleDefaultCalClick");
201 @@ -746,6 +872,50 @@ var PrefsAssistant = Class.create({
202         
203         // *** WIDGET ATTRS & MODELS
204  
205 +       notificationRepeatIntervals: [
206 +               {label:$L('Disabled'), command:'0'},
207 +               {label:$L('5 Seconds'), command:'.083'},
208 +               {label:$L('10 Seconds'), command:'.167'},
209 +               {label:$L('15 Seconds'), command:'.25'},
210 +               {label:$L('20 Seconds'), command:'.333'},
211 +               {label:$L('25 Seconds'), command:'.417'},
212 +               {label:$L('30 Seconds'), command:'.5'},
213 +               {label:$L('1 Minutes'), command:'1'},
214 +               {label:$L('2 Minutes'), command:'2'},
215 +               {label:$L('3 Minutes'), command:'3'},
216 +               {label:$L('4 Minutes'), command:'4'},
217 +               {label:$L('5 Minutes'), command:'5'},
218 +               {label:$L('10 Minutes'), command:'10'},
219 +               {label:$L('15 Minutes'), command:'15'}
220 +       ],
221 +       
222 +       notificationMaxRepeats: [
223 +               {label:$L('Unlimited'), command:'99999'}, //this should be a large enough value to be conisdered unlimited for our purpose.
224 +               {label:$L('1'), command:'1'},
225 +               {label:$L('2'), command:'2'},
226 +               {label:$L('3'), command:'3'},
227 +               {label:$L('4'), command:'4'},
228 +               {label:$L('5'), command:'5'},
229 +               {label:$L('10'), command:'10'},
230 +               {label:$L('15'), command:'15'},
231 +               {label:$L('20'), command:'20'},
232 +               {label:$L('25'), command:'25'},
233 +               {label:$L('30'), command:'30'},
234 +               {label:$L('35'), command:'35'},
235 +               {label:$L('40'), command:'40'},
236 +               {label:$L('45'), command:'45'},
237 +               {label:$L('50'), command:'50'},
238 +               {label:$L('55'), command:'55'},
239 +               {label:$L('60'), command:'60'},
240 +               {label:$L('65'), command:'65'},
241 +               {label:$L('70'), command:'70'},
242 +               {label:$L('75'), command:'75'},
243 +               {label:$L('80'), command:'80'},
244 +               {label:$L('85'), command:'85'},
245 +               {label:$L('90'), command:'90'},
246 +               {label:$L('95'), command:'95'},
247 +               {label:$L('100'), command:'100'}
248 +       ],
249         
250         acctsListAttrs : {
251                 itemTemplate: 'prefs/prefs-account',
252 diff --git a/usr/palm/applications/com.palm.app.calendar/app/controllers/reminder-assistant.js b/usr/palm/applications/com.palm.app.calendar/app/controllers/reminder-assistant.js
253 index d190fd1..1b28853 100644
254 --- a/usr/palm/applications/com.palm.app.calendar/app/controllers/reminder-assistant.js
255 +++ b/usr/palm/applications/com.palm.app.calendar/app/controllers/reminder-assistant.js
256 @@ -1,5 +1,6 @@
257  /* Copyright 2009 Palm, Inc.  All rights reserved. */
258  
259 +g_notificationRepeatCount = 0;
260  
261  var ReminderAssistant = Class.create({
262         initialize: function(eventId,needThrobbing) {
263 @@ -28,6 +29,40 @@ var ReminderAssistant = Class.create({
264         
265         setup: function() {
266                 Mojo.Log.info("$$$$$$$$ Reminder-assistant setup:start");
267 +               
268 +               //load the notification repeat preferences.
269 +               //doing this here instead of in initialze to avoid conflict with snooze duration patch
270 +               //get notification repeat interval and max repeat values from cookie
271 +               this.notificationCookie = new Mojo.Model.Cookie("com.palm.app.calendar.notificationrepeat");
272 +               
273 +               if (this.notificationCookie) 
274 +               {
275 +                       var notificationCookie = this.notificationCookie.get();
276 +
277 +                       if (notificationCookie) 
278 +                       {                       
279 +                               if(notificationCookie.notificationRepeatInterval)
280 +                               {
281 +                                       this.notificationRepeatInterval = notificationCookie.notificationRepeatInterval;
282 +                               }
283 +                               else
284 +                               {
285 +                                       //set default value to 2 minutes
286 +                                       this.notificationRepeatInterval = '2';
287 +                               }
288 +                               
289 +                               if(notificationCookie.notificationMaxRepeat)
290 +                               {
291 +                                       this.notificationMaxRepeat = notificationCookie.notificationMaxRepeat;
292 +                               }
293 +                               else
294 +                               {
295 +                                       //set default value to unlimited
296 +                                       this.notificationMaxRepeat = '99999';
297 +                               }
298 +                       }
299 +               }
300 +               
301                 this.service = getCalendarService();
302  
303                 this.reminders.observeReminders('alert', this);
304 @@ -60,6 +95,9 @@ var ReminderAssistant = Class.create({
305                         }
306                 }
307                 Mojo.Log.info("$$$$$$$$ Reminder-assistant cleanup:end:");
308 +
309 +               //remove the Notification repeat task
310 +               this.removePlayAlarmSoundTask();
311         },
312         
313         remindersUpdated: function() {
314 @@ -95,6 +133,9 @@ var ReminderAssistant = Class.create({
315                 this.scheduleAutoCloseTask();
316                 this.updateDisplay();
317                 Mojo.Log.info("$$$$$$$$ Reminder-assistant updateMostRecentReminder:end");
318 +
319 +               //setup the notification repeat task
320 +               this.schedulePlayAlarmSoundTask();
321         },
322  
323         updateDisplay: function() {
324 @@ -373,6 +414,13 @@ var ReminderAssistant = Class.create({
325                 this.reminders.stopObservingReminders('alert');
326                 Mojo.Log.info("$$$$$$$$ Reminder-assistant closeAlert: window.close() ");
327                 this.controller.window.close();
328 +               
329 +               //reset the notification repeat counter
330 +               if( this.dismissed || this.snoozed )
331 +               {
332 +                       g_notificationRepeatCount = 0;
333 +               }
334 +                       
335                 Mojo.Log.info("$$$$$$$$ Reminder-assistant closeAlert: end ");
336         },
337         
338 @@ -383,6 +431,13 @@ var ReminderAssistant = Class.create({
339                 Mojo.Log.info("$$$$$$$$ Reminder-assistant autoCloseAlert: end " + this.reminder.id);
340         },
341         
342 +       playAlarmSound: function() {
343 +               //temporarily set the snooze to 0 will immediately re-trigger allert to get our attention.
344 +               this.dismissed = false;
345 +               this.DEFAULT_SNOOZE = 0;
346 +               this.closeAlert();
347 +       },
348 +
349         specialCleanup:function(){
350                 //we need to do this so that cleanup cleans the reminder rightaway              
351                 Mojo.Log.info("$$$$$$$$ Reminder-assistant specialCleanup: window Name:" + this.controller.window.name);
352 @@ -432,6 +487,35 @@ var ReminderAssistant = Class.create({
353                 Mojo.Log.info("$$$$$$$$ Reminder-assistant removeAutoCloseTask: end " + this.reminder.id);
354         },
355         
356 +       schedulePlayAlarmSoundTask: function() {
357 +               //retrigger reminder every X minutes until we acknowledge it.
358 +               //notificationRepeatInterval disables the notification repeat
359 +               //also check to make sure we have not exceeded the max repeat value
360 +               if( parseFloat(this.notificationRepeatInterval) != 0 && g_notificationRepeatCount < parseInt(this.notificationMaxRepeat))
361 +               {
362 +                       g_notificationRepeatCount++;
363 +                       
364 +                       var playSoundTime = new Date();
365 +                       playSoundTime = new Date(playSoundTime.getTime() + parseFloat(this.notificationRepeatInterval)*60*1000);
366 +
367 +                       this.controller.serviceRequest('palm://com.palm.taskScheduler', {
368 +                               method: 'updateTask',
369 +                               parameters: {uri: 'palm://com.palm.applicationManager/open',
370 +                               arguments: {'id': 'com.palm.app.calendar',
371 +                                               'params': {'playalarmsound': 'true'}},
372 +                               key: 'calendar-playalarmsound',
373 +                               start: {date: playSoundTime.toUTCString()}}
374 +                       });
375 +               }
376 +       },
377 +
378 +       removePlayAlarmSoundTask: function() {
379 +               this.controller.serviceRequest('palm://com.palm.taskScheduler', {
380 +                       method: 'removeTask',
381 +                       parameters: {key: 'calendar-playalarmsound'}
382 +               });
383 +       },
384 +
385         replaceHTML: function(element, content) {
386                 Mojo.Log.info("$$$$$$$$ Reminder-assistant replaceHTML:start");
387         var range = element.ownerDocument.createRange();
388 diff --git a/usr/palm/applications/com.palm.app.calendar/app/views/prefs/prefs-scene.html b/usr/palm/applications/com.palm.app.calendar/app/views/prefs/prefs-scene.html
389 index 3f1e673..9383d50 100644
390 --- a/usr/palm/applications/com.palm.app.calendar/app/views/prefs/prefs-scene.html
391 +++ b/usr/palm/applications/com.palm.app.calendar/app/views/prefs/prefs-scene.html
392 @@ -42,6 +42,25 @@
393         </div>
394  </div>
395  
396 +<div id='pv_notificationrepeat_div' class="palm-group">
397 +       <div class="palm-group-title" x-mojo-loc="">Notification Repeat</div>
398 +               <div class="palm-list">
399 +                       <div id="pv_notification_repeat_interval" class="palm-row">
400 +                               <div class="palm-row-wrapper">
401 +                                               <div class="label" x-mojo-loc="">Repeat Interval</div>
402 +                                               <div id="pv_notification_repeat_interval_value" class="title"></div>
403 +                               </div>
404 +                       </div>
405 +                       
406 +                       <div id="pv_notification_max_repeat" class="palm-row">
407 +                               <div class="palm-row-wrapper">
408 +                                               <div class="label" x-mojo-loc="">Max Repeats</div>
409 +                                               <div id="pv_notification_max_repeat_value" class="title"></div>
410 +                               </div>
411 +                       </div>
412 +               </div>
413 +</div> 
414 +
415  <div id='pv_defaulteventalarm_div' class="palm-group">
416         <div class="palm-group-title" x-mojo-loc="">Default event reminder</div>
417                 <div class="palm-list">