javascript LoanerUtils使用数组的类和方法示例
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript LoanerUtils使用数组的类和方法示例相关的知识,希望对你有一定的参考价值。
var LoanerUtils = Class.create();
LoanerUtils.prototype = {
/**********
* Initialization stuff here...
*
**********/
initialize : function() {
this.overdueRemindTime = gs.getProperty('x_cdltd_loaner_req.overdue.remindtime', 24) * 60 * 60 * 1000;
this.pickupLeadTime = gs.getProperty('x_cdltd_loaner_req.pickup.leadtime', 24) * 60 * 60 * 1000;
this.returnRemindTime = gs.getProperty('x_cdltd_loaner_req.return.remindtime', 24) * 60 * 60 * 1000;
this.appScopeName = gs.getCurrentScopeName();
this.loanerTableName = this.appScopeName + '_loaner_request';
this.pickupEvent = this.appScopeName + '.pickup';
this.returnEvent = this.appScopeName + '.return';
this.remindEvent = this.appScopeName + '.reminder';
this.overdueEvent = this.appScopeName + '.overdue';
},
/**********
*
* getOverdueRequests - retrieve a list of overdue records
*
* @param - None
* @return: array of sys_ids
*
**********/
getOverdueRequests : function() {
var a = [];
var gr = new GlideRecord(this.loanerTableName);
var rightNow = new GlideDateTime().getDisplayValue();
gr.addQuery('end_date', '<=', rightNow);
gr.addQuery('state', 17);
gr.query();
while (gr.next()) {
a.push(gr.sys_id.toString());
}
return a;
},
/**********
*
* timeToRemindOverdue - Use the passed in ID to check if the record is time to remind again
*
* @param - id: sys_id of the loaner record to check
* @return - boolean: true = time to remind
*
**********/
timeToRemindOverdue : function(id) {
var gr = new GlideRecord(this.loanerTableName);
var noticeTime = new GlideDateTime();
var tempDate = noticeTime.add(this.overdueRemindTime) + '';
if (!gr.get(id)) {
gs.log('>>>DEBUG: LoanerUtils: timeToRemindOverdue(): FAILED TO RETRIEVE RECORD');
return false;
}
var baseDate = (gr.last_overdue_reminder == '') ? gr.end_date : gr.last_overdue_reminder;
return (baseDate <= tempDate) ? true : false;
},
/**********
*
* sendOverdueReminder - Queue an event to send a reminder and update the necessary
* record fields to indicate they've been reminded
*
* @param - id: sys_id of the loaner record to check
* @return - None
*
**********/
sendOverdueReminder : function(id) {
var gr = new GlideRecord(this.loanerTableName);
if (!gr.get(id)) {
gs.log('>>>DEBUG: LoanerUtils: setLastOverdueReminder(): FAILED TO RETRIEVE RECORD');
return;
}
++gr.overdue_count;
// Record the last time a reminder was sent
gr.last_overdue_reminder = new GlideDateTime().getDisplayValue();
gr.update();
// Send the overdue reminder
gs.eventQueue(this.overdueEvent, gr, gr.start_date, gr.end_date);
},
/**********
*
* getNullPickupReminders - Get a list of records in state 'Ready for Pickup'
* that haven't been reminded before
*
* @param - None
* @return - array of sys_ids
*
**********/
getNullPickupReminders : function() {
var a = [];
var gr = new GlideRecord(this.loanerTableName);
var noticeTime = new GlideDateTime();
noticeTime.add(this.pickupLeadTime);
gr.addQuery('state', 16);
gr.addQuery('pick_up_reminder', '');
gr.addQuery('start_date', '<=', noticeTime);
gr.query();
while (gr.next()) {
a.push(gr.sys_id.toString());
}
return a;
},
/**********
*
* sendPickupReminder - Queue an event to send a reminder and update the pickup reminder field
*
* @param - id: sys_id of the loaner record to check
* @return - None
*
**********/
sendPickupReminder : function(id) {
var gr = new GlideRecord(this.loanerTableName);
if (!gr.get(id)) {
gs.debug('>>>DEBUG: LoanerUtils: sendPickupReminder(): FAILED TO RETRIEVE RECORD');
return;
}
// Log the time the pickup reminder was sent and avoid sending again
gr.pick_up_reminder = new GlideDateTime().getDisplayValue();
gr.update();
// Send the pickup reminder
gs.eventQueue(this.pickupEvent, gr, gr.start_date, gr.end_date);
return;
},
/**********
*
* getNullReturnReminders - Get a list of records that need reminding to bring their item back
*
* @param - None
* @return - array of sys_ids
*
**********/
getNullReturnReminders : function() {
var a = [];
var gr = new GlideRecord(this.loanerTableName);
var noticeTime = new GlideDateTime();
var tempDate = noticeTime.add(this.returnRemindTime) + '';
gr.addQuery('state', 17);
gr.addQuery('return_reminder', '');
gr.addQuery('end_date', '<=', tempDate);
gr.query();
while (gr.next()) {
a.push(gr.sys_id.toString());
}
return a;
},
/**********
*
* setReturnReminder - Queue a return reminder and update field when reminder was sent
*
* @param - id: sys_id of the loaner record to check
* @return - None
*
**********/
sendReturnReminder : function(id) {
var gr = new GlideRecord(this.loanerTableName);
if (!gr.get(id)) {
gs.debug('>>>DEBUG: LoanerUtils: sendReturnReminder(): FAILED TO RETRIEVE RECORD');
return;
}
// Set this record to never remind again
gr.return_reminder = new GlideDateTime().getDisplayValue();
gr.update();
// Send the return reminder
gs.eventQueue(this.returnEvent, gr, gr.start_date, gr.end_date);
},
type: 'LoanerUtils'
};
以上是关于javascript LoanerUtils使用数组的类和方法示例的主要内容,如果未能解决你的问题,请参考以下文章
使用 JavaScript 显示 HTML 文本框中剩余的字符数
利用JavaScript打印出Fibonacci数(不使用全局变量)