How to use snooze method in wpt

Best JavaScript code snippet using wpt

ZmReminderDialog.js

Source:ZmReminderDialog.js Github

copy

Full Screen

1/*2 * ***** BEGIN LICENSE BLOCK *****3 * Zimbra Collaboration Suite Web Client4 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011, 2012 VMware, Inc.5 * 6 * The contents of this file are subject to the Zimbra Public License7 * Version 1.3 ("License"); you may not use this file except in8 * compliance with the License. You may obtain a copy of the License at9 * http://www.zimbra.com/license.10 * 11 * Software distributed under the License is distributed on an "AS IS"12 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.13 * ***** END LICENSE BLOCK *****14 */15/**16* show history of the status window17* @param parent the element that created this view18 * @private19*/20ZmReminderDialog = function(parent, reminderController, calController, apptType) {21 // init custom buttons22 this._apptType = apptType;23 var selectInputId = "ZmReminderDialog_reminderSelectInput_" + apptType;24 var selectButtonId = "ZmReminderDialog_reminderSelectBtn_" + apptType;25 var html = [];26 var i = 0;27 html[i++] = "<td valign='middle' class='ZmReminderField'>";28 html[i++] = ZmMsg.snoozeAll;29 html[i++] = "</td><td valign='middle'>";30 // Use a table within a dialog button td to cause the selector input field and drop31 // down button to align properly and butt up against one another.32 html[i++] = "<table cellspacing=0 cellpadding=0><tr></tr><td valign='middle' id='";33 html[i++] = selectInputId;34 html[i++] = "'></td><td valign='middle' id='";35 html[i++] = selectButtonId;36 html[i++] = "'></td></tr></table>";37 html[i++] = "</td><td valign='middle' class='ZmSnoozeButton' id=\"{0}\"></td>";38 var snoozeButton = new DwtDialog_ButtonDescriptor(ZmReminderDialog.SNOOZE_BUTTON, ZmMsg.snooze, DwtDialog.ALIGN_LEFT, null, html.join(""));39 var dismissAllButton = new DwtDialog_ButtonDescriptor(ZmReminderDialog.DISMISS_ALL_BUTTON, ZmMsg.dismissAll, DwtDialog.ALIGN_RIGHT);40 // call base class41 DwtDialog.call(this, {id:"ZmReminderDialog_" + apptType, parent:parent, standardButtons:DwtDialog.NO_BUTTONS, extraButtons:[snoozeButton, dismissAllButton]});42 this._reminderController = reminderController;43 this._calController = calController;44 this.setContent(this._contentHtml(selectInputId, selectButtonId));45 if(this._calController instanceof ZmTaskMgr) {46 this.setTitle(ZmMsg.taskReminders);47 } else {48 this.setTitle(ZmMsg.apptReminders);49 }50 this.registerCallback(ZmReminderDialog.SNOOZE_BUTTON, this._handleSnoozeButton, this);51 this.registerCallback(ZmReminderDialog.DISMISS_ALL_BUTTON, this._handleDismissAllButton, this);52};53ZmReminderDialog.prototype = new DwtDialog;54ZmReminderDialog.prototype.constructor = ZmReminderDialog;55// Consts56ZmReminderDialog.SNOOZE_BUTTON = "Snooze";//++DwtDialog.LAST_BUTTON;57ZmReminderDialog.DISMISS_ALL_BUTTON = "DismissAll";//++DwtDialog.LAST_BUTTON;58ZmReminderDialog.SOON = -AjxDateUtil.MSEC_PER_FIFTEEN_MINUTES;59// Public methods60ZmReminderDialog.prototype.toString =61function() {62 return "ZmReminderDialog";63};64ZmReminderDialog.prototype.popup =65function() {66 DwtDialog.prototype.popup.call(this);67 this._cancelSnooze();68 if (appCtxt.get(ZmSetting.CAL_REMINDER_NOTIFY_BROWSER)) {69 AjxPackage.require("Alert");70 ZmBrowserAlert.getInstance().start(ZmMsg.reminders);71 }72 if (appCtxt.get(ZmSetting.CAL_REMINDER_NOTIFY_SOUNDS)) {73 AjxPackage.require("Alert");74 ZmSoundAlert.getInstance().start();75 }76 if (appCtxt.get(ZmSetting.CAL_REMINDER_NOTIFY_TOASTER)) {77 AjxPackage.require("Alert");78 var winText = [];79 var appts = this._list.getArray();80 // only show, at most, five appointment reminders81 for (var i = 0; i < appts.length && i < 5; i++) {82 var appt = appts[i];83 var startDelta = this._computeDelta(appt);84 var delta = startDelta ? this._formatDeltaString(startDelta) : "";85 var text = [appt.getName(), ", ", this._getDurationText(appt), "\n(", delta, ")"].join("");86 if (AjxEnv.isMac) {87 ZmDesktopAlert.getInstance().start(ZmMsg.reminders, text, true);88 } else if (AjxEnv.isWindows) {89 winText.push(text);90 }91 }92 if (AjxEnv.isWindows && winText.length > 0) {93 if (appts.length > 5) {94 winText.push(ZmMsg.andMore);95 }96 ZmDesktopAlert.getInstance().start(ZmMsg.reminders, winText.join("\n"), true);97 }98 }99 var snoozeSelectMenuListener = this._snoozeSelectMenuListener.bind(this);100 this._createSnoozeMenu(this._snoozeSelectButton, snoozeSelectMenuListener, this._list);101};102ZmReminderDialog.prototype.initialize =103function(list) {104 this._list = new AjxVector();105 this._apptData = {};106 var html = [];107 var idx = 0;108 var size = list.size();109 AjxDebug.println(AjxDebug.REMINDER, "---Reminders [" + (new Date().getTime())+ "]---");110 html[idx++] = "<table cellpadding=0 cellspacing=0 border=0 width=100%>";111 for (var i = 0; i < size; i++) {112 var appt = list.get(i);113 if (appt.isShared() && appt.isReadOnly()) { continue; }114 this._list.add(appt);115 var uid = appt.getUniqueId(true);116 var data = this._apptData[uid] = {appt:appt};117 idx = this._addAppt(html, idx, appt, data, (i > 0));118 }119 html[idx++] = "</table>";120 // cleanup before using121 if (this._dismissButtons) {122 for (var id in this._dismissButtons) {123 this._dismissButtons[id].dispose();124 }125 }126 if (this._openButtons) {127 for (var id in this._openButtons) {128 this._openButtons[id].dispose();129 }130 }131 this._dismissButtons = {};132 this._openButtons = {};133 var dismissListener = new AjxListener(this, this._dismissButtonListener);134 var openListener = new AjxListener(this, this._openButtonListener);135 var div = document.getElementById(this._listId);136 div.innerHTML = html.join("");137 for (var i = 0; i < size; i++) {138 var appt = list.get(i);139 var uid = appt.getUniqueId(true);140 var id = appt.id;141 var data = this._apptData[uid];142 if (!data) { continue; }143 var alarmData = appt.getAlarmData();144 alarmData = (alarmData && alarmData.length > 0) ? alarmData[0] : {};145 //bug: 60692 - Add troubleshooting code for late reminders146 AjxDebug.println(AjxDebug.REMINDER, appt.getReminderName() + " : " + (alarmData.nextAlarm || " NA ") + " / " + (alarmData.alarmInstStart || " NA "));147 // dismiss button148 var dismissBtn = this._dismissButtons[data.dismissBtnId] = new DwtButton({id:"dismissBtn_" + id, parent:this, className:"DwtToolbarButton", parentElement:data.dismissBtnId});149 dismissBtn.setText(ZmMsg.dismiss);150 dismissBtn.addSelectionListener(dismissListener);151 dismissBtn.apptUid = uid;152 // open button153 var openBtn = this._openButtons[data.openBtnId] = new DwtButton({id:"openBtn_" + id, parent:this, className:"DwtToolbarButton", parentElement:data.openBtnId});154 openBtn.setText(ZmMsg.viewAppointment);155 openBtn.addSelectionListener(openListener);156 openBtn.apptUid = uid;157 this._updateDelta(data);158 }159 var snoozeSelectMenuListener = this._snoozeSelectMenuListener.bind(this);160 this._createSnoozeMenu(this._snoozeSelectButton, snoozeSelectMenuListener, this._list);161};162ZmReminderDialog.prototype._contentHtml =163function(selectInputId, selectButtonId) {164 this._listId = Dwt.getNextId("ZmReminderDialogContent");//Dwt.getNextId();165 var params = {166 parent: this,167 parentElement: selectInputId,168 type: DwtInputField.STRING,169 errorIconStyle: DwtInputField.ERROR_ICON_NONE,170 validationStyle: DwtInputField.CONTINUAL_VALIDATION,171 className: "DwtInputField ReminderInput"172 };173 this._snoozeSelectInput = new DwtInputField(params);174 var snoozeInputEl = this._snoozeSelectInput.getInputElement();175 Dwt.setSize(snoozeInputEl, Dwt.DEFAULT, "22px");176 var snoozeSelectButtonListener = this._snoozeSelectButtonListener.bind(this);177 this._snoozeSelectButton = this._createSnoozeSelectButton(this, selectButtonId,178 snoozeSelectButtonListener);179 return ["<div class='ZmReminderDialog' id='", this._listId, "'>"].join("");180};181ZmReminderDialog.prototype._createSnoozeSelectButton =182function(parent, buttonId, buttonListener) {183 var snoozeSelectButton = new DwtButton({parent:parent});184 snoozeSelectButton.addDropDownSelectionListener(buttonListener);185 snoozeSelectButton.setData(Dwt.KEY_ID, buttonId);186 snoozeSelectButton.reparentHtmlElement(buttonId);187 //this._createSnoozeMenu(snoozeSelectButton, menuSelectionListener);188 return snoozeSelectButton;189}190ZmReminderDialog.DEFAULT_SNOOZE = -5;191ZmReminderDialog.SNOOZE_MINUTES =192// Snooze period in minutes (negative is 'minutes before appt', zero is separator:193 [-30, -15, -5, -1, 0,194 1, 5, 10, 15, 30, 45, 60, 120, 240, 480, 1440, 2880, 4320, 5760, 10080, 20160];195// 1hr 2hr 4hr 8hr 1day 2days 3days 4days 1week 2weeks196// Snooze period in msec (Entries must match SNOOZE_MINUTES)197ZmReminderDialog.SNOOZE_MSEC =198 [ -30*60*1000, -15*60*1000, -5*60*1000, -1*60*1000, 0,199 1*60*1000, 5*60*1000, 10*60*1000, 15*60*1000, 30*60*1000, 45*60*1000, 60*60*1000,200 120*60*1000, 240*60*1000, 480*60*1000, 1440*60*1000, 2880*60*1000, 4320*60*1000, 5760*60*1000,201 10080*60*1000, 20160*60*1000];202// Minutes per: minute hour day week endMarker203ZmReminderDialog.SCALE_MINUTES = [ 1, 60, 1440, 10080, 1000000];204ZmReminderDialog.prototype._createSnoozeMenu =205function(snoozeSelectButton, menuSelectionListener, apptList) {206 // create menu for button207 var snoozeMenu = new DwtMenu({parent:snoozeSelectButton, style:DwtMenu.DROPDOWN_STYLE});208 snoozeMenu.setSize("150");209 snoozeSelectButton.setMenu(snoozeMenu, true);210 var appts = apptList.getArray();211 var minStartDelta = 1;212 if (this._apptType == "task") {213 // Tasks are simpler: No 'before' times allowed, and all fixed times are allowed214 minStartDelta = 1;215 } else {216 for (var i = 0; i < appts.length; i++) {217 var appt = appts[i];218 var startDelta = this._computeDelta(appt);219 // Only limit the snooze menu with appts that have not already started/completed220 if (startDelta < 0) {221 // Limit the list of 'before' times by the appt that will appear the soonest in the future222 if ((startDelta > minStartDelta) || (minStartDelta >= 0)) {223 minStartDelta = startDelta;224 }225 // Get the largest snooze period that can be used by any appt (without snoozing past its start)226 startDelta = -startDelta;227 }228 }229 }230 var snoozeFormatter = [];231 var snoozeFormatterBefore = new AjxMessageFormat(ZmMsg.apptRemindNMinutesBefore); // Before Appt Formatter232 snoozeFormatter[0] = new AjxMessageFormat(ZmMsg.reminderSnoozeMinutes); // Minute Formatter233 snoozeFormatter[1] = new AjxMessageFormat(ZmMsg.reminderSnoozeHours); // Hour Formatter234 snoozeFormatter[2] = new AjxMessageFormat(ZmMsg.reminderSnoozeDays); // Day Formatter235 snoozeFormatter[3] = new AjxMessageFormat(ZmMsg.reminderSnoozeWeeks); // Week Formatter236 var iFormatter = 0;237 var formatter = null;238 var snoozeDisplayValue = 0;239 var scale = 1;240 var defaultSet = false;241 var firstMenuItem = null;242 var addSeparator = false;243 var anyAdded = false;244 for (var i = 0; i < ZmReminderDialog.SNOOZE_MINUTES.length; i++) {245 if (ZmReminderDialog.SNOOZE_MSEC[i] >= minStartDelta) {246 // Found a snooze period to display247 snoozeDisplayValue = ZmReminderDialog.SNOOZE_MINUTES[i];248 if (snoozeDisplayValue == 0) {249 // Set up to add a separator if any 'before' time were added; do the250 // actual add if any fixed times are added251 addSeparator = anyAdded;252 }253 else {254 if (addSeparator) {255 new DwtMenuItem({parent:snoozeMenu, style:DwtMenuItem.SEPARATOR_STYLE});256 addSeparator = false;257 }258 anyAdded = true;259 if (snoozeDisplayValue <= 0) {260 snoozeDisplayValue = -snoozeDisplayValue;261 formatter = snoozeFormatterBefore;262 scale = 1;263 }else {264 if (snoozeDisplayValue >= ZmReminderDialog.SCALE_MINUTES[iFormatter+1]) {265 iFormatter++;266 }267 scale = ZmReminderDialog.SCALE_MINUTES[iFormatter];268 formatter = snoozeFormatter[iFormatter];269 }270 var label = formatter.format(snoozeDisplayValue/scale);271 var mi = new DwtMenuItem({parent: snoozeMenu, style: DwtMenuItem.NO_STYLE});272 mi.setText(label);273 mi.setData("value", snoozeDisplayValue);274 if(menuSelectionListener) mi.addSelectionListener(menuSelectionListener);275 if (!firstMenuItem) {276 // Set the first item as the default277 firstMenuItem = mi;278 mi.setChecked(true);279 this._snoozeSelectInput.setValue(label);280 defaultSet = true;281 }282 }283 }284 }285 if (firstMenuItem == null) {286 // No valid selections287 this._snoozeSelectInput.setValue("");288 this._snoozeSelectInput.setEnabled(false, true);289 snoozeMenu.setEnabled(false, true);290 snoozeSelectButton.setEnabled(false);291 this.setButtonEnabled(ZmReminderDialog.SNOOZE_BUTTON, false);292 this.unregisterCallback(ZmReminderDialog.SNOOZE_BUTTON);293 } else {294 this._snoozeSelectInput.setEnabled(true, true);295 snoozeMenu.setEnabled(true, true);296 snoozeSelectButton.setEnabled(true, true);297 this.setButtonEnabled(ZmReminderDialog.SNOOZE_BUTTON, true);298 this.registerCallback(ZmReminderDialog.SNOOZE_BUTTON, this._handleSnoozeButton, this);299 }300};301ZmReminderDialog.prototype._snoozeSelectButtonListener =302function(ev) {303 ev.item.popup();304};305ZmReminderDialog.prototype._snoozeSelectMenuListener =306function(ev) {307 if (ev.item && ev.item instanceof DwtMenuItem) {308 this._snoozeSelectInput.setValue(ev.item.getText());309 this._snoozeValue = ev.item.getData("value");310 return;311 }312};313ZmReminderDialog.prototype._updateDelta =314function(data) {315 var td = document.getElementById(data.deltaId);316 if (td) {317 var startDelta = this._computeDelta(data.appt);318 if (startDelta >= 0) td.className = 'ZmReminderOverdue';319 else if (startDelta > ZmReminderDialog.SOON) td.className = 'ZmReminderSoon';320 else td.className = 'ZmReminderFuture';321 td.innerHTML = startDelta ? this._formatDeltaString(startDelta) : "";322 }323};324ZmReminderDialog.prototype._addAppt =325function(html, idx, appt, data, needSep) {326 var uid = appt.id;327 data.dismissBtnId = "dismissBtnContainer_" + uid;328 data.openBtnId = "openBtnContainer_" + uid;329 data.deltaId = "delta_" + uid;330 data.rowId = "apptRow_" + uid;331 data.reminderNameContainerId = "reminderNameContainerId_" + uid;332 data.reminderDescContainerId = "reminderDescContainerId_" + uid;333 var calName = (appt.folderId != ZmOrganizer.ID_CALENDAR && appt.folderId != ZmOrganizer.ID_TASKS && this._calController)334 ? this._calController.getCalendarName(appt.folderId) : null;335 var calendar = appCtxt.getById(appt.folderId);336 var params = {337 needSep: needSep,338 rowId: data.rowId,339 calName: AjxStringUtil.htmlEncode(calName),340 accountName: (appCtxt.multiAccounts && calendar && calendar.getAccount().getDisplayName()),341 location: (AjxStringUtil.htmlEncode(appt.getReminderLocation())),342 apptIconHtml: (AjxImg.getImageHtml(appt.otherAttendees ? "ApptMeeting" : "Appointment")),343 organizer: appt.otherAtt ? appt.organizer : null,344 reminderName: (AjxStringUtil.htmlEncode(appt.getReminderName())),345 durationText: (AjxStringUtil.trim(this._getDurationText(appt))),346 deltaId: data.deltaId,347 openBtnId: data.openBtnId,348 dismissBtnId: data.dismissBtnId,349 reminderNameContainerId: data.reminderNameContainerId,350 reminderDescContainerId: data.reminderDescContainerId,351 type: appt.type ? appt.type : ZmItem.APPT352 };353 html[idx++] = AjxTemplate.expand("calendar.Calendar#ReminderDialogRow", params);354 return idx;355};356ZmReminderDialog.prototype._openButtonListener =357function(ev) {358 appCtxt.getAppController().setStatusMsg(ZmMsg.allRemindersAreSnoozed, ZmStatusView.LEVEL_INFO);359 this._handleSnoozeButton();360 var obj = DwtControl.getTargetControl(ev);361 var data = this._apptData[obj.apptUid];362 var appt = data ? data.appt : null;363 var type = appt.type ? appt.type : ZmItem.APPT;364 if (appt && type == ZmItem.APPT) {365 AjxDispatcher.require(["CalendarCore", "Calendar"]);366 var cc = AjxDispatcher.run("GetCalController");367 // the give appt object is a ZmCalBaseItem. We need a ZmAppt368 var newAppt = new ZmAppt();369 for (var i in appt) {370 if (!AjxUtil.isFunction(appt[i])) {371 newAppt[i] = appt[i];372 }373 }374 var mode = newAppt.isRecurring() ? ZmCalItem.MODE_EDIT_SINGLE_INSTANCE : null;375 var callback = new AjxCallback(cc, cc._showAppointmentDetails, newAppt);376 newAppt.getDetails(mode, callback, null, null, true);377 } else if(appt && type == ZmItem.TASK) {378 AjxDispatcher.require(["TasksCore", "Tasks"]);379 var tlc = AjxDispatcher.run("GetTaskListController");380 // the give appt object is a ZmCalBaseItem. We need a ZmAppt381 var newTask = new ZmTask();382 for (var i in appt) {383 if (!AjxUtil.isFunction(appt[i])) {384 newTask[i] = appt[i];385 }386 }387 var callback = new AjxCallback(tlc, tlc._editTask, newTask);388 newTask.getDetails(null, callback, null, null, true);389 }390};391ZmReminderDialog.prototype._dismissButtonListener =392function(ev) {393 var obj = DwtControl.getTargetControl(ev);394 var data = this._apptData[obj.apptUid];395 if (!data) { return; }396 this._reminderController.dismissAppt(data.appt);397 // cleanup HTML398 var dismissBtn = this._dismissButtons[data.dismissBtnId];399 if (dismissBtn) {400 dismissBtn.dispose();401 delete this._dismissButtons[data.dismissBtnId];402 }403 var openBtn = this._openButtons[data.openBtnId];404 if (openBtn) {405 openBtn.dispose();406 delete this._openButtons[data.openBtnId];407 }408 var row = document.getElementById(data.rowId);409 if (row) {410 var nextRow = row.nextSibling;411 if (nextRow && nextRow.getAttribute("name") == "rdsep") {412 nextRow.parentNode.removeChild(nextRow);413 }414 row.parentNode.removeChild(row);415 }416 delete this._apptData[obj.apptUid];417 this._list.remove(data.appt);418 if (this._list.size() == 0) {419 this.popdown();420 }421};422ZmReminderDialog.prototype._handleSnoozeButton =423function() {424 // check if all fields are populated w/ valid values425 var errorMsg = [];426 var snoozeInfo = null;427 var beforeAppt = false;428 var snoozeString = this._snoozeSelectInput.getValue();429 if (!snoozeString) {430 errorMsg.push(ZmMsg.reminderSnoozeClickNoDuration);431 } else {432 snoozeInfo = ZmCalendarApp.parseReminderString(snoozeString);433 if (snoozeInfo.reminderValue === "" ) {434 // Returned when no number was specified in the snooze input field435 errorMsg.push(ZmMsg.reminderSnoozeClickNoNumber);436 } else {437 // Test if the unit is a known one (default behaviour for parseReminderString438 // returns unknowns as hours)439 var valid = this._testSnoozeString(snoozeString);440 if (!valid) {441 errorMsg.push(ZmMsg.reminderSnoozeClickUnknownUnit);442 } else {443 // Detect 'before'444 beforeAppt = (snoozeString.indexOf('before') >= 0);445 }446 }447 }448 if (errorMsg.length > 0) {449 var msg = errorMsg.join("<br>");450 var dialog = appCtxt.getMsgDialog();451 dialog.reset();452 dialog.setMessage(msg, DwtMessageDialog.WARNING_STYLE);453 dialog.popup();454 } else {455 this.popdown();456 var snoozeMinutes = ZmCalendarApp.convertReminderUnits(snoozeInfo.reminderValue,457 snoozeInfo.reminderUnits);458 this._reminderController.snoozeAppt(this._list);459 this._reminderController._snoozeApptAction(this._list, snoozeMinutes, beforeAppt)460 }461};462/**463 * Parses the given string to insure the units are recognized464 * @param snoozeString snooze string eg. "10 minutes"465 *466 * @private467 */468ZmReminderDialog.prototype._testSnoozeString =469function(snoozeString) {470 var snoozeUnitStrings = [];471 snoozeUnitStrings[0] = AjxMsg.minute;472 snoozeUnitStrings[1] = AjxMsg.hour;473 snoozeUnitStrings[2] = AjxMsg.day;474 snoozeUnitStrings[3] = AjxMsg.week;475 // Plural476 snoozeUnitStrings[4] = AjxMsg.minutes;477 snoozeUnitStrings[5] = AjxMsg.hours;478 snoozeUnitStrings[6] = AjxMsg.days;479 snoozeUnitStrings[7] = AjxMsg.weeks;480 snoozeString = snoozeString.toLowerCase();481 var found = false;482 for (var i = 0; i < snoozeUnitStrings.length; i++) {483 if (snoozeString.indexOf(snoozeUnitStrings[i].toLowerCase()) >= 0) {484 found = true;485 break;486 }487 }488 return found;489};490ZmReminderDialog.prototype._snoozeAction =491function(list) {492 if (list) {493 this._reminderController.activateSnoozedAppts(list);494 }495};496ZmReminderDialog.prototype._cancelSnooze =497function() {498 if (this._snoozeActionId) {499 AjxTimedAction.cancelAction(this._snoozeActionId);500 delete this._snoozeActionId;501 }502};503ZmReminderDialog.prototype._handleDismissAllButton =504function() {505 this._cancelSnooze();506 this.popdown();507 this._reminderController.dismissAppt(this._list);508};509ZmReminderDialog.prototype._getDurationText =510function(appt) {511 var isMultiDay = appt.isMultiDay();512 var start = appt._alarmInstStart ? new Date(appt._alarmInstStart) : appt.startDate ? appt.startDate : null;513 // bug: 28598 - alarm for recurring appt might still point to old alarm time514 // cannot take endTime directly515 var endTime = appt._alarmInstStart ? (start.getTime() + appt.getDuration()) : appt.getEndTime();516 var end = new Date(endTime);517 //for task518 if(appt.type == ZmItem.TASK && !start && !endTime) { return null; }519 if (appt.isAllDayEvent()) {520 end = appt.type != ZmItem.TASK ? new Date(endTime - (isMultiDay ? 2 * AjxDateUtil.MSEC_PER_HOUR : 0)) : end;521 var pattern = isMultiDay ? ZmMsg.apptTimeAllDayMulti : ZmMsg.apptTimeAllDay;522 return start ? AjxMessageFormat.format(pattern, [start, end]) : AjxMessageFormat.format(pattern, [end]); //for task523 }524 var pattern = isMultiDay ? ZmMsg.apptTimeInstanceMulti : ZmMsg.apptTimeInstance;525 return AjxMessageFormat.format(pattern, [start, end, ""]);526};527ZmReminderDialog.prototype._computeDelta =528function(appt) {529 return (appt.alarmData && appt.alarmData.length > 0)530 ? (appt.alarmData[0].alarmInstStart ? (new Date()).getTime() - appt.adjustMS(appt.alarmData[0].alarmInstStart, appt.tzo) : appt.getEndTime() ? (new Date()).getTime() - appt.getEndTime() : null)531 : ((new Date()).getTime() - appt.getStartTime());532};533ZmReminderDialog.prototype._formatDeltaString =534function(deltaMSec) {535 var prefix = deltaMSec < 0 ? "In" : "OverdueBy";536 deltaMSec = Math.abs(deltaMSec);537 // calculate parts538 var years = Math.floor(deltaMSec / (AjxDateUtil.MSEC_PER_DAY * 365));539 if (years != 0)540 deltaMSec -= years * AjxDateUtil.MSEC_PER_DAY * 365;541 var months = Math.floor(deltaMSec / (AjxDateUtil.MSEC_PER_DAY * 30.42));542 if (months > 0)543 deltaMSec -= Math.floor(months * AjxDateUtil.MSEC_PER_DAY * 30.42);544 var days = Math.floor(deltaMSec / AjxDateUtil.MSEC_PER_DAY);545 if (days > 0)546 deltaMSec -= days * AjxDateUtil.MSEC_PER_DAY;547 var hours = Math.floor(deltaMSec / AjxDateUtil.MSEC_PER_HOUR);548 if (hours > 0)549 deltaMSec -= hours * AjxDateUtil.MSEC_PER_HOUR;550 var mins = Math.floor(deltaMSec / 60000);551 if (mins > 0)552 deltaMSec -= mins * 60000;553 var secs = Math.floor(deltaMSec / 1000);554 if (secs > 30 && mins < 59) mins++;555 var secs = 0;556 // determine message557 var amount;558 if (years > 0) {559 amount = "Years";560 if (years <= 3 && months > 0) {561 amount = "YearsMonths";562 }563 } else if (months > 0) {564 amount = "Months";565 if (months <= 3 && days > 0) {566 amount = "MonthsDays";567 }568 } else if (days > 0) {569 amount = "Days";570 if (days <= 2 && hours > 0) {571 amount = "DaysHours";572 }573 } else if (hours > 0) {574 amount = "Hours";575 if (hours < 5 && mins > 0) {576 amount = "HoursMinutes";577 }578 } else {579 amount = "Minutes";580 }581 // format message582 var key = ["reminder",prefix,amount].join("");583 var args = [deltaMSec, years, months, days, hours, mins, secs];584 return AjxMessageFormat.format(ZmMsg[key], args);585};586//Bug 65466: Method overridden to remove the ESC button behavior587ZmReminderDialog.prototype.handleKeyAction =588function(actionCode, ev) {589 switch (actionCode) {590 case DwtKeyMap.ENTER:591 this.notifyListeners(DwtEvent.ENTER, ev);592 break;593 case DwtKeyMap.CANCEL:594 // Dont do anything595 break;596 case DwtKeyMap.YES:597 if (this._buttonDesc[DwtDialog.YES_BUTTON]) {598 this._runCallbackForButtonId(DwtDialog.YES_BUTTON);599 }600 break;601 case DwtKeyMap.NO:602 if (this._buttonDesc[DwtDialog.NO_BUTTON]) {603 this._runCallbackForButtonId(DwtDialog.NO_BUTTON);604 }605 break;606 default:607 return false;608 }609 return true;...

Full Screen

Full Screen

notifications.test.js

Source:notifications.test.js Github

copy

Full Screen

1var should = require('should');2var Stream = require('stream');3var levels = require('../lib/levels');4describe('notifications', function ( ) {5 var env = {testMode: true};6 var ctx = {7 bus: new Stream8 , ddata: {9 lastUpdated: Date.now()10 }11 };12 var notifications = require('../lib/notifications')(env, ctx);13 function examplePlugin () {}14 var exampleInfo = {15 title: 'test'16 , message: 'testing'17 , level: levels.INFO18 , plugin: examplePlugin19 };20 var exampleWarn = {21 title: 'test'22 , message: 'testing'23 , level: levels.WARN24 , plugin: examplePlugin25 };26 var exampleUrgent = {27 title: 'test'28 , message: 'testing'29 , level: levels.URGENT30 , plugin: examplePlugin31 };32 var exampleSnooze = {33 level: levels.WARN34 , title: 'exampleSnooze'35 , message: 'exampleSnooze message'36 , lengthMills: 1000037 };38 var exampleSnoozeNone = {39 level: levels.WARN40 , title: 'exampleSnoozeNone'41 , message: 'exampleSnoozeNone message'42 , lengthMills: 143 };44 var exampleSnoozeUrgent = {45 level: levels.URGENT46 , title: 'exampleSnoozeUrgent'47 , message: 'exampleSnoozeUrgent message'48 , lengthMills: 1000049 };50 function expectNotification (check, done) {51 //start fresh to we don't pick up other notifications52 ctx.bus = new Stream;53 //if notification doesn't get called test will time out54 ctx.bus.on('notification', function callback (notify) {55 if (check(notify)) {56 done();57 }58 });59 }60 function clearToDone (done) {61 expectNotification(function expectClear (notify) {62 return notify.clear;63 }, done);64 }65 function notifyToDone (done) {66 expectNotification(function expectNotClear (notify) {67 return ! notify.clear;68 }, done);69 }70 it('initAndReInit', function (done) {71 notifications.initRequests();72 notifications.requestNotify(exampleWarn);73 notifications.findHighestAlarm().should.equal(exampleWarn);74 notifications.initRequests();75 should.not.exist(notifications.findHighestAlarm());76 done();77 });78 it('emitAWarning', function (done) {79 //start fresh to we don't pick up other notifications80 ctx.bus = new Stream;81 //if notification doesn't get called test will time out82 ctx.bus.on('notification', function callback ( ) {83 done();84 });85 notifications.resetStateForTests();86 notifications.initRequests();87 notifications.requestNotify(exampleWarn);88 notifications.findHighestAlarm().should.equal(exampleWarn);89 notifications.process();90 });91 it('emitAnInfo', function (done) {92 notifyToDone(done);93 notifications.resetStateForTests();94 notifications.initRequests();95 notifications.requestNotify(exampleInfo);96 should.not.exist(notifications.findHighestAlarm());97 notifications.process();98 });99 it('emitAllClear 1 time after alarm is auto acked', function (done) {100 clearToDone(done);101 notifications.resetStateForTests();102 notifications.initRequests();103 notifications.requestNotify(exampleWarn);104 notifications.findHighestAlarm().should.equal(exampleWarn);105 notifications.process();106 notifications.initRequests();107 //don't request a notify this time, and an auto ack should be sent108 should.not.exist(notifications.findHighestAlarm());109 notifications.process();110 var alarm = notifications.getAlarmForTests(levels.WARN);111 alarm.level.should.equal(levels.WARN);112 alarm.silenceTime.should.equal(1);113 alarm.lastAckTime.should.be.approximately(Date.now(), 2000);114 should.not.exist(alarm.lastEmitTime);115 //clear last emit time, even with that all clear shouldn't be sent again since there was no alarm cleared116 delete alarm.lastEmitTime;117 //process 1 more time to make sure all clear is only sent once118 notifications.initRequests();119 //don't request a notify this time, and an auto ack should be sent120 should.not.exist(notifications.findHighestAlarm());121 notifications.process();122 });123 it('Can be snoozed', function (done) {124 notifyToDone(done); //shouldn't get called125 notifications.resetStateForTests();126 notifications.initRequests();127 notifications.requestNotify(exampleWarn);128 notifications.requestSnooze(exampleSnooze);129 notifications.snoozedBy(exampleWarn).should.equal(exampleSnooze);130 notifications.process();131 done();132 });133 it('Can be snoozed by last snooze', function (done) {134 notifyToDone(done); //shouldn't get called135 notifications.resetStateForTests();136 notifications.initRequests();137 notifications.requestNotify(exampleWarn);138 notifications.requestSnooze(exampleSnoozeNone);139 notifications.requestSnooze(exampleSnooze);140 notifications.snoozedBy(exampleWarn).should.equal(exampleSnooze);141 notifications.process();142 done();143 });144 it('Urgent alarms can\'t be snoozed by warn', function (done) {145 clearToDone(done); //shouldn't get called146 notifications.resetStateForTests();147 notifications.initRequests();148 notifications.requestNotify(exampleUrgent);149 notifications.requestSnooze(exampleSnooze);150 should.not.exist(notifications.snoozedBy(exampleUrgent));151 notifications.process();152 done();153 });154 it('Warnings can be snoozed by urgent', function (done) {155 notifyToDone(done); //shouldn't get called156 notifications.resetStateForTests();157 notifications.initRequests();158 notifications.requestNotify(exampleWarn);159 notifications.requestSnooze(exampleSnoozeUrgent);160 notifications.snoozedBy(exampleWarn).should.equal(exampleSnoozeUrgent);161 notifications.process();162 done();163 });...

Full Screen

Full Screen

parser.js

Source:parser.js Github

copy

Full Screen

1//Written by Edwin Jones - http://edwinjones.me.uk2'use strict';3const log = require('debug')('parser');4const chrono = require('chrono-node');5const moment = require('moment');6//we use these regexes to repeatedly find the words 'until' and 'for' in a string7//only when they are NOT part of other words8const untilRegex = new RegExp("\\b" + "until" + "\\b");9const forRegex = new RegExp("\\b" + "for" + "\\b");10//This function uses the above regexes to replace words in our snooze string11//so it will work better with chrono-node12const cleanSnoozeString = (snoozeString) => {13 snoozeString = snoozeString.replace(untilRegex, "at");14 snoozeString = snoozeString.replace(forRegex, "in");15 return snoozeString;16}17/**18 * Use this function to check to see if a reminder string is valid19 *20 * @param {string} reminderString the string to validate. Must contain a message and time.21 * @returns {boolean} a boolean value representing if the reminder string is valid or not.22 */23module.exports.validReminderString = (reminderString) => {24 let parsedDate = chrono.parse(reminderString, new Date(), { forwardDate: true })[0];25 if (parsedDate == undefined) {26 return false;27 }28 //remove whitespace from message29 let reminderMessage = reminderString.replace(parsedDate.text, "").trim();30 //remove all unprintable chars from message (ASCII 32-127 ONLY)31 reminderMessage = reminderMessage.replace(/[^\x20-\x7F]/g, "");32 if (!reminderMessage) {33 return false;34 }35 let reminderTime = moment(parsedDate.start.date());36 if (!reminderTime.isValid() || reminderTime <= new Date()) {37 return false;38 }39 return true;40}41/**42 * Use this function to get the reminder message from a valid reminder string43 *44 * @param {String} reminderString the string to validate. Must contain a message and time.45 * @returns {{message: String, date: Date}} the message and date that should be used for the reminder.46 */47module.exports.getMessageAndDateFromReminderString = (reminderString) => {48 if (!this.validReminderString(reminderString)) {49 throw new Error("Invalid reminder string!");50 }51 let parsedDate = chrono.parse(reminderString, new Date(), { forwardDate: true })[0];52 let message = reminderString.replace(parsedDate.text, "").trim();53 let date = parsedDate.start.date();54 return { message: message, date: date };55}56/**57 * Use this function to check to see if a snooze string is valid58 *59 * @param {string} snoozeString the string to validate. Must contain a time.60 * @returns {boolean} a boolean value representing if the snooze string is valid or not.61 */62module.exports.validSnoozeString = (snoozeString) => {63 snoozeString = cleanSnoozeString(snoozeString);64 let parsedDate = chrono.parse(snoozeString, new Date(), { forwardDate: true })[0];65 if (parsedDate == undefined) {66 return false;67 }68 let snoozeUntilTime = moment(parsedDate.start.date());69 if (!snoozeUntilTime.isValid() || snoozeUntilTime <= new Date()) {70 return false;71 }72 return true;73}74/**75 * Use this function to get the time/date to snooze until from a valid snooze string76 *77 * @param {String} snoozeString the string to parse. Must contain a time.78 * @returns {Date} the date that should be used to snooze the reminder for/until.79 */80module.exports.getDateFromSnoozeString = (snoozeString) => {81 if (!this.validSnoozeString(snoozeString)) {82 throw new Error("Invalid snooze string!");83 }84 let parsedDate = chrono.parse(cleanSnoozeString(snoozeString), new Date(), { forwardDate: true })[0];85 let date = parsedDate.start.date();86 return date;...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var sleep = wptoolkit.sleep;3var wptoolkit = require('wptoolkit');4var snooze = wptoolkit.snooze;5var wptoolkit = require('wptoolkit');6var wait = wptoolkit.wait;7var wptoolkit = require('wptoolkit');8var waitUntil = wptoolkit.waitUntil;9var wptoolkit = require('wptoolkit');10var waitWhile = wptoolkit.waitWhile;11var wptoolkit = require('wptoolkit');12var waitUntilElement = wptoolkit.waitUntilElement;13var wptoolkit = require('wptoolkit');14var waitWhileElement = wptoolkit.waitWhileElement;15var wptoolkit = require('wptoolkit');16var waitUntilText = wptoolkit.waitUntilText;17var wptoolkit = require('wptoolkit');18var waitWhileText = wptoolkit.waitWhileText;19var wptoolkit = require('wptoolkit');20var waitUntilElementText = wptoolkit.waitUntilElementText;21var wptoolkit = require('wptoolkit');22var waitWhileElementText = wptoolkit.waitWhileElementText;23var wptoolkit = require('wptoolkit');24var waitUntilTitle = wptoolkit.waitUntilTitle;25var wptoolkit = require('wptoolkit');26var waitWhileTitle = wptoolkit.waitWhileTitle;

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptoolkit = require('wptoolkit');2var snooze = wptoolkit.snooze;3snooze(5000);4snooze(10000);5snooze(15000);6snooze(20000);7snooze(25000);8snooze(30000);9snooze(35000);10snooze(40000);11snooze(45000);12snooze(50000);13snooze(55000);14snooze(60000);15snooze(65000);16snooze(70000);17snooze(75000);18snooze(80000);19snooze(85000);20snooze(90000);21snooze(95000);22snooze(100000);23snooze(105000);24snooze(110000);25snooze(115000);26snooze(120000);27snooze(125000);28snooze(130000);29snooze(135000);30snooze(140000);31snooze(145000);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wiki = wptools.page('Barack Obama');3wiki.get(function(err, data) {4 console.log(data);5});6var wptools = require('wptools');7var wiki = wptools.page('Barack Obama');8wiki.get(function(err, data) {9 console.log(data);10});11var wptools = require('wptools');12var wiki = wptools.page('Barack Obama');13wiki.get(function(err, data) {14 console.log(data);15});16var wptools = require('wptools');17var wiki = wptools.page('Barack Obama');18wiki.get(function(err, data) {19 console.log(data);20});21var wptools = require('wptools');22var wiki = wptools.page('Barack Obama');23wiki.get(function(err, data) {24 console.log(data);25});26var wptools = require('wptools');27var wiki = wptools.page('Barack Obama');28wiki.get(function(err, data) {29 console.log(data);30});31var wptools = require('wptools');32var wiki = wptools.page('Barack Obama');33wiki.get(function(err, data) {34 console.log(data);35});36var wptools = require('wptools');37var wiki = wptools.page('Barack Obama');38wiki.get(function(err, data) {39 console.log(data);40});41var wptools = require('wptools');42var wiki = wptools.page('Barack Obama');43wiki.get(function(err, data) {44 console.log(data);45});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert_Einstein');3page.snooze().then(function(info) {4 console.log(info);5});6var wptools = require('wptools');7var page = wptools.page('Albert_Einstein');8page.get().then(function(info) {9 console.log(info);10});11var wptools = require('wptools');12var page = wptools.page('Albert_Einstein');13page.get().then(function(info) {14 console.log(info);15});16var wptools = require('wptools');17var page = wptools.page('Albert_Einstein');18page.get().then(function(info) {19 console.log(info);20});21var wptools = require('wptools');22var page = wptools.page('Albert_Einstein');23page.get().then(function(info) {24 console.log(info);25});26var wptools = require('wptools');27var page = wptools.page('Albert_Einstein');28page.get().then(function(info) {29 console.log(info);30});31var wptools = require('wptools');32var page = wptools.page('Albert_Einstein');33page.get().then(function(info) {34 console.log(info);35});36var wptools = require('wptools');37var page = wptools.page('Albert_Einstein');38page.get().then(function(info) {39 console.log(info);40});41var wptools = require('wptools');42var page = wptools.page('Albert_Einstein');43page.get().then(function(info) {44 console.log(info);45});46var wptools = require('wpt

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Barack Obama');3page.snooze(3000).then(function() {4 console.log('I waited 3 seconds');5});6var wptools = require('wptools');7var page = wptools.page('Barack Obama');8page.snooze(3000).then(function() {9 console.log('I waited 3 seconds');10});11var wptools = require('wptools');12var page = wptools.page('Barack Obama');13page.snooze(3000).then(function() {14 console.log('I waited 3 seconds');15});16var wptools = require('wptools');17var page = wptools.page('Barack Obama');18page.snooze(3000).then(function() {19 console.log('I waited 3 seconds');20});21var wptools = require('wptools');22var page = wptools.page('Barack Obama');23page.snooze(3000).then(function() {24 console.log('I waited 3 seconds');25});26var wptools = require('wptools');27var page = wptools.page('Barack Obama');28page.snooze(3000).then(function() {29 console.log('I waited 3 seconds');30});31var wptools = require('wptools');32var page = wptools.page('Barack Obama');33page.snooze(3000).then(function() {34 console.log('I waited 3 seconds');35});36var wptools = require('wptools');37var page = wptools.page('Barack Obama');38page.snooze(3000).then(function() {39 console.log('I waited 3 seconds');40});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var page = wptools.page('Albert Einstein');3page.get(function(err, resp) {4 console.log(resp);5});6npm ERR! at Error (native)7npm ERR! { [Error: EACCES: permission denied, open '/home/pi/.npm/wptools/0.0.5/package.tgz.1001443661']8npm ERR! path: '/home/pi/.npm/wptools/0.0.5/package.tgz.1001443661' }

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('webpagetest-api').create('www.webpagetest.org', 'A.1c0d7f2e6d7c7f0d8f1b7e9cbf7f7d8d');2var options = {3 videoParams: {4 }5};6wpt.runTest(testUrl, options, function(err, data) {7 if (err) {8 return console.error(err);9 }10 console.log(data);11 wpt.getTestResults(data.data.testId, function(err, data) {12 if (err) {13 return console.error(err);14 }15 console.log(data);16 });17});18var options = {19 videoParams: {20 }21};22wpt.runTest(testUrl, options, function(err, data) {23 if (err) {24 return console.error(err);25 }26 console.log(data);27 wpt.getTestResults(data.data.testId, function(err, data) {28 if (err) {29 return console.error(err);30 }31 console.log(data);32 });33});34wpt.snoozeTest(data.data.testId, 10, function(err, data) {35 if (err) {36 return console.error(err);37 }38 console.log(data);39 wpt.getTestResults(data.data.testId, function(err, data) {40 if (err) {41 return console.error(err);42 }43 console.log(data);44 });45});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful