SC.MODULE_INFO['cloudos_foundation/alarms'].source = "/**\n * @license Portions of this software are copyright Yahoo, Inc, used under the following license:\n * Software License Agreement (BSD License)\n * Copyright (c) 2009, Yahoo! Inc.\n * All rights reserved.\n * Redistribution and use of this software in source and binary forms, with or without modification, are permitted provided that the following conditions are met:\n *\n * Redistributions of source code must retain the above copyright notice, this list of conditions and the\n * following disclaimer.\n * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.\n * Neither the name of Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission of Yahoo! Inc.\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n *\n * Sources of Intellectual Property Included in the YUI Library\n * Where not otherwise indicated, all YUI content is authored by Yahoo! engineers and consists of Yahoo!-owned intellectual property. YUI is issued by Yahoo! under the BSD license above. In some specific instances, YUI will incorporate work done by developers outside of Yahoo! with their express permission.\n*/\n\n/*!\n * jQuery JavaScript Library v1.8.3\n * http://jquery.com/\n *\n * Includes Sizzle.js\n * http://sizzlejs.com/\n *\n * Copyright 2012 jQuery Foundation and other contributors\n * Released under the MIT license\n * http://jquery.org/license\n *\n * Date: Tue Nov 13 2012 08:20:33 GMT-0500 (Eastern Standard Time)\n */\n/*! @license\n * URI.js - Mutating URLs\n *\n * Version: 1.18.1\n *\n * Author: Rodney Rehm\n * Web: http://medialize.github.io/URI.js/\n *\n * Published under the MIT License http://www.opensource.org/licenses/mit-license\n *\n */\n\n/*! @license\n Copyright Mathias Bynens \n \n Permission is hereby granted, free of charge, to any person obtaining\n a copy of this software and associated documentation files (the\n \"Software\"), to deal in the Software without restriction, including\n without limitation the rights to use, copy, modify, merge, publish,\n distribute, sublicense, and/or sell copies of the Software, and to\n permit persons to whom the Software is furnished to do so, subject to\n the following conditions:\n \n The above copyright notice and this permission notice shall be\n included in all copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n*/\n\n/*!\n * @license\n *\n * ]{ UUID - Ultra liteweight, blazing fast JavaScript UUID v4 generator\n * https://bitbucket.org/kodifica/uuid/\n *\n * Copyright 2009-2010 Massimo Lombardo\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nSC.stringsFor(\"en-us\",{\"Alarms.Today.Message\":\"“%{eventTitle}” at %{date:h}:%{date:mm} %{date:a}\",\"Alarms.Tomorrow.Message\":\"“%{eventTitle}” tomorrow at %{date:h}:%{date:mm} %{date:a}\",\"Alarms.Future.Message\":\"“%{eventTitle}” on %{date:MM}/%{date:dd}/%{date:yyyy} at %{date:h}:%{date:mm} %{date:a}\"}),CloudOS.Alarms=SC.Object.create({ALARMS_FETCH_AFTER_INTERVAL:861e5,DISPLAY_PAST_ALARMS_THRESHOULD:-31e3,DISTANCE_FROM_BUTTONS:14,BUTTON_LONG_TEXT_MARGIN:24,SMALL_BUTTON_MIN_WIDTH:57,dateRangeForAlarmsRequest:function(){var e=new Date,t=\"%@1-%@2-%@3\".fmt(e.getFullYear(),e.getMonth()+1,e.getDate()),n;return e.setHours(e.getHours()+24),n=\"%@1-%@2-%@3\".fmt(e.getFullYear(),e.getMonth()+1,e.getDate()),{startDate:t,endDate:n}},getCompleteMessageString:function(e,t){var n=e.title;n&&(n=SC.RenderContext.escapeHTML(n),n.length>100&&(n=n.substr(0,100)+\"…\"));if(!t||SC.typeOf(t)!==SC.T_ARRAY)return n;var r=new Date,i=r.getDate(),s=r.getMonth()+1,o=r.getFullYear(),u=new Date(o,s-1,i,0,0,0,0),a=u.getTime();u.setHours(u.getHours()+24);var f=u.getTime();u.setHours(u.getHours()+24);var l=u.getTime(),c=new Date(t[1],t[2]-1,t[3],0,t[6],0,0),h=c.getTime(),p;return h>=a&&h=f&&h=l?p=\"Alarms.Future.Message\".loc({eventTitle:n,date:c,dateFormatter:SC.DateFormatter}):SC.error(\"This event alarm with guid [%@1] is for a past alarms and it should not have been returned in the fetch call.\",e.guid),p},initializeAlarmControllers:function(\n){var e=CloudOS.notificationsController,t=e.shouldDisplayNotification(\"calendar\"),n=e.shouldDisplayNotification(\"reminders\");CW.notificationCenter.subscribeToNotification(\"notificationsPreferenceDidChange\",this,this.initializeAlarmControllers),t&&CloudOS.Alarms.calendarAlarmsController.fetchUpcomingAlarmsAndScheduleNextFetch(),n&&CloudOS.Alarms.remindersAlarmsController.fetchUpcomingAlarmsAndScheduleNextFetch()}}),CloudOS.Alarms.iOSNotification=CloudOS.iOSNotification.extend({alarmObject:null,itemStartDate:function(){var e=this.get(\"alarmObject\");return e?e.localStartDate||e.startDate:null}.property(\"alarmObject\").cacheable(),message:function(e,t){if(t!==undefined)this._msg=t;else if(!this._msg){var n=this.get(\"alarmObject\"),r=this.get(\"itemStartDate\");n&&r?this._msg=CloudOS.Alarms.getCompleteMessageString(n,r):this._msg=null}return this._msg}.property(\"alarmObject\",\"itemStartDate\").cacheable(),contentView:SC.View.extend({classNames:\"action-buttons\",useStaticLayout:YES,layout:{width:\"auto\",right:0,top:0,height:57},childViews:[\"dismissAlarm\",\"snoozeAlarm\"],dismissAlarm:SC.ButtonView.design({layout:{height:27,centerY:SC.browser.mozilla?0:1},useStaticLayout:YES,classNames:\"dismiss-button bar-before button-aligned-right\",themeName:\"borderless\",isDefault:YES,title:\"Button.Close\".loc(),action:\"dismissAlarm\",controlSize:SC.LARGE_CONTROL_SIZE}),snoozeAlarm:SC.ButtonView.design({layout:{height:27,centerY:SC.browser.mozilla?0:1},useStaticLayout:YES,classNames:\"snooze-button button-in-between\",themeName:\"borderless\",title:\"Button.Snooze\".loc(),action:\"snoozeAlarm\",controlSize:SC.LARGE_CONTROL_SIZE\n}),didAppendToDocument:function(){this.invokeLast(function(){var e=this.get(\"parentView\"),t=e.$(\".message\"),n=e.$(\".description\"),r=this.get(\"dismissAlarm\"),i=r.$(\".sc-button-label\"),s=this.get(\"snoozeAlarm\"),o=s.$(\".sc-button-label\"),u=CloudOS.Alarms.DISTANCE_FROM_BUTTONS,a,f,l,c,h=t.attr(\"style\")||\"\",p=n.attr(\"style\")||\"\";i&&i.length>0&&o&&o.length>0&&(a=i[0].offsetWidth,f=o[0].offsetWidth,c=a+f+u,e.set(\"rightMarginForMessageText\",c),l=\"right: \"+c+\"px\",t.attr(\"style\",h+l),e.get(\"description\")?n.attr(\"style\",p+l):t.addClass(\"no-description-text\"))})}})}),CloudOS.Alarms.BaseController=SC.Object.extend({_implicitPeriodicScheduler:null,_upcomingAlarms:[],_scheduledAlarmTimers:null,appManager:function(){var e=this.get(\"appName\");return CloudOS.appManagerFor(e)}.property().cacheable(),alarmIcon:function(){return this.getPath(\"appManager.notificationIcon\")}.property().cacheable(),fetchUpcomingAlarmsAndScheduleNextFetch:function(){var e=this.get(\"dataSource\"),t=CW.notificationCenter,n=this._implicitPeriodicScheduler;if(!e){SC.error(\"fetchUpcomingAlarmsAndScheduleNextFetch(): No datasource attached to controller.\");return}e.fetchAlarms(this.get(\"appName\"),this.fetchAlarmsSuccessCallback,this.fetchAlarmsFailureCallback),n&&n.invalidate(),this._implicitPeriodicScheduler=SC.Timer.schedule({target:this,action:\"fetchUpcomingAlarmsAndScheduleNextFetch\",interval:CloudOS.Alarms.ALARMS_FETCH_AFTER_INTERVAL}),t.subscribeToNotification(\"didReceivePushNotification\",this,this.pushNotificationReceived),t.subscribeToNotification(\"notificationsPreferenceDidChange\",this,this.invalidateAllScheduledAlarms\n)},refreshUpcomingAlarms:function(){this.invalidateAllScheduledAlarms(),this.scheduleAllAlarms()}.observes(\"_upcomingAlarms\"),invalidateAllScheduledAlarms:function(){SC.debug(\"* invalidateAllScheduledAlarms for : %@\",this.get(\"appName\"));var e=this._schedulediOSNotificationsHash,t=this._upcomingAlarms,n,r=[],i,s,o=this._scheduledAlarmTimers,u;t.length>0&&t.forEach(function(t){n=t.guid,u=e[n],u&&(u.get(\"content\")!==t&&(s=CW.hashDifferencesBreakdown(u.get(\"content\"),t).different),s&&s.length>0?(SC.info(\"Since something in the currently enqueued alarm [%@1] changed, we will remove it from the queue and schedule it again.\",t.guid),e[n].remove(),delete e[n]):r.push(n))});for(n in e)r.indexOf(n)<0&&(i=e[n],i&&(SC.info(\"The alarm with guid [%@] was missing in the last fetch call. So, we will remove it from the notification queue.\",n),i.remove(),delete e[n]));o&&(o.forEach(function(e){e.invalidate()}),this._scheduledAlarmTimers=null)},scheduleAllAlarms:function(){SC.debug(\"* scheduleAllAlarms for : %@\",this.get(\"appName\"));var e=this._upcomingAlarms;if(!e)return;var t=this,n=this._schedulediOSNotificationsHash,r=[],i=this.get(\"alarmIcon\"),s=(new Date).getTime(),o,u;e.forEach(function(e){var a=e.localEndDate||e.startDate,f=30;if(!a){SC.warn(\"* scheduleAllAlarms : itemEndDate is Not Available \");return}var l=new Date(a[1],a[2]-1,a[3],a[4],a[5],f,0),c=l.getTime();if(s>c)return;u=n?n[e.guid]:null;if(!u){o=e.triggerDate;var h=new Date(o[1],o[2]-1,o[3],0,o[6],0,0),p=h.getTime(),d=e.localStartDate||e.startDate,v=CloudOS.Alarms.getCompleteMessageString(e,d);if(!v){SC.error(\"Since Message is not there we cannot schedule an alarm\"\n);return}r.push(SC.Timer.schedule({startTime:p,target:this,action:function(){var n=CloudOS.Alarms.iOSNotification.create({appDisplayName:t.getPath(\"appManager.displayName\"),alarmObject:e,description:SC.RenderContext.escapeHTML(e.location),icon:i,automaticallyDismiss:NO,isDismissable:YES,acceptsFirstResponder:YES,dismissAlarm:function(){this.remove(),t.acknowledgeAlarm(this.get(\"content\"))},snoozeAlarm:function(){this.remove(),t.snoozeAlarm(this.get(\"content\"))},action:function(e){t.showItemInParentApp(e)},didCreateLayer:function(){var e=arguments.callee.base.apply(this,arguments),n=t.get(\"appName\"),r=t.get(\"appManager\");return n===\"reminders\"&&!r.get(\"isReady\")&&(SC.debug(\"* Reminders app is not running yet, so launching it in background to update badge count\"),r.getReadyInBackground()),e}});n.set(\"content\",e),t._schedulediOSNotificationsHash[e.guid]=n,CW.iOSNotification.enqueue(n),SC.info(\"Enqueued iOSNotification for alarm trigger at %@1\",h)}})),t.set(\"_scheduledAlarmTimers\",r),SC.info(\"An upcoming %@1 alarm is scheduled on %@2\",t.get(\"appName\"),h)}})},acknowledgeAlarm:function(e){var t=this.get(\"dataSource\");t.acknowledgeAlarm(e,this.get(\"appName\"))},snoozeAlarm:function(e){var t=this.get(\"dataSource\");t.snoozeAlarm(e,this.get(\"appName\"))},pushNotificationReceived:function(e){var t=this.get(\"appName\");if(e.indexOf(t)===-1)return;SC.debug(\"%@ alarm controller: pushNotificationReceived, invalidating old alarms and fetching updates\",t),this._implicitPeriodicScheduler&&this._implicitPeriodicScheduler.invalidate(),this.fetchUpcomingAlarmsAndScheduleNextFetch()}}),CloudOS.Alarms\n.calendarAlarmsController=CloudOS.Alarms.BaseController.create({dataSourceBinding:\"CloudOS.Alarms.calendarDataSource\",appName:\"calendar\",_schedulediOSNotificationsHash:{},fetchAlarmsSuccessCallback:function(e){var t=e.get(\"body\");return t&&SC.typeOf(t.AlarmTrigger)===SC.T_ARRAY&&CloudOS.Alarms.calendarAlarmsController.set(\"_upcomingAlarms\",t.AlarmTrigger),YES},fetchAlarmsFailureCallback:function(e){return SC.info(\"Fetch Calendar alarms failed with a status code %@1.\",e.get(\"status\")),YES},showItemInParentApp:function(e){SC.debug(\"Loading calendar application and highlight the event to which the alarm belongs.\");var t=CloudOS.appController,n=e.get(\"content\"),r=n.guid,i={icloud:{type:\"Event\",collectionGuid:n.pGuid,pGuid:r.substr(0,r.indexOf(\":\"))}};t.switchToApplicationWithNotification(this.get(\"appName\"),i,e)}}),CloudOS.Alarms.remindersAlarmsController=CloudOS.Alarms.BaseController.create({dataSourceBinding:\"CloudOS.Alarms.remindersDataSource\",appName:\"reminders\",_schedulediOSNotificationsHash:{},fetchAlarmsSuccessCallback:function(e){var t=e.get(\"body\");return t&&SC.typeOf(t.AlarmTrigger)===SC.T_ARRAY&&CloudOS.Alarms.remindersAlarmsController.set(\"_upcomingAlarms\",t.AlarmTrigger),YES},fetchAlarmsFailureCallback:function(e){return SC.info(\"Fetch Reminders alarms failed with a status code %@1.\",e.get(\"status\")),YES},showItemInParentApp:function(e){SC.debug(\"Loading reminders application and highlight the reminder to which the alarm belongs.\");var t=CloudOS.appController,n=e.get(\"content\"),r=n.guid,i={};i={icloud:{type:\"Reminder\",collectionGuid:n.pGuid,reminderGuid:r.substr(0,r\n.indexOf(\":\"))}},t.switchToApplicationWithNotification(this.get(\"appName\"),i,e)}}),CloudOS.Alarms.DataSource=SC.Object.extend({prepareRequest:function(e,t,n){var r=CloudOS.authController;e.queryParameter(\"dsid\",r.getPath(\"user.dsid\")),e.queryParameter(\"usertz\",r.getPath(\"accountPreferences.timeZone\")),e.queryParameter(\"lang\",SC.Locale.currentLocale.language),e.set(\"reportRequest\",YES),e.notify(200,this,t),e.notify(0,this,n)},fetchAlarms:function(e,t,n){if(!CloudOS.authController.get(\"isAtLeastPartiallyAuthenticated\")){SC.info(\"COS: Cannot fetch Alarms since we are no longer authenticated.\");return}var r=CK.servicesController.getServiceUrlFor(e)+this.fetchAlarmsUrl,i=CloudOS.Alarms.dateRangeForAlarmsRequest(),s=COS.Request.getUrl(r);s.set(\"isJSON\",YES),s.queryParameter(\"startDate\",i.startDate),s.queryParameter(\"endDate\",i.endDate),this.prepareRequest(s,t,n),s.send()},acknowledgeAlarm:function(e,t){var n={pGuid:e.pGuid,guid:e.guid},r=CK.servicesController.getServiceUrlFor(t)+this.acknowledgeAlarmUrl,i=COS.Request.postUrl(r,n);i.set(\"serviceName\",t),this.prepareRequest(i,this.acknowledgeAlarmSucceeded,this.acknowledgeAlarmFailed),i.send()},acknowledgeAlarmSucceeded:function(e){return SC.debug(\"Successfully acknowledged the alarm.\"),YES},acknowledgeAlarmFailed:function(e){return SC.info(\"Acknowledging alarm failed with a status code %@1.\",e.get(\"status\")),YES},snoozeAlarm:function(e,t){var n={pGuid:e.pGuid,guid:e.guid},r=CK.servicesController.getServiceUrlFor(t)+this.snoozeAlarmUrl,i=COS.Request.postUrl(r,n);i.set(\"serviceName\",t),this.prepareRequest(i,this.snoozeAlarmSucceeded,\nthis.snoozeAlarmFailed),i.send()},snoozeAlarmSucceeded:function(e){return SC.info(\"Alarm snooze was successful\"),YES},snoozeAlarmFailed:function(e){return SC.info(\"Alarm snooze failed with a status code %@1.\",e.get(\"status\")),YES}}),CloudOS.Alarms.calendarDataSource=CloudOS.Alarms.DataSource.create({fetchAlarmsUrl:\"/ca/alarmtriggers/\",acknowledgeAlarmUrl:\"/ca/acknowledgeAlarm/\",snoozeAlarmUrl:\"/ca/snoozealarm/\"}),CloudOS.Alarms.remindersDataSource=CloudOS.Alarms.DataSource.create({fetchAlarmsUrl:\"/rd/alarmtriggers/\",acknowledgeAlarmUrl:\"/rd/acknowledgeAlarm/\",snoozeAlarmUrl:\"/rd/snoozealarm/\",acknowledgeAlarmSucceeded:function(){arguments.callee.base.apply(this,arguments),CloudOS.Alarms.remindersAlarmsController.fetchUpcomingAlarmsAndScheduleNextFetch()}});\n";