-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaeonRequestsDialog.js
More file actions
566 lines (519 loc) · 25.7 KB
/
aeonRequestsDialog.js
File metadata and controls
566 lines (519 loc) · 25.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
(function( $ ){
"use strict";
var methods = {
init : function( options ) {
var $this = this, data = this.data('aeonRequestsDialog'), settings;
// If the plugin hasn't been initialized yet
if ( ! data ) {
settings = $.extend( {
//general settings
'url': '',
'dialogId': 'aeon_request_dialog',
'submitButtonSelector': '.aeon_submit',
'AeonForm': 'EADRequest',
'RequestType': 'Loan',
'globalFields': [],
'itemFields': [],
'items': [],
'datasource': 'form',
//form processing
'form': 'EADRequest',
'requestsSelector':'input[name="Request"]',
//json processing
'jsonUrl': null,
'jsonCallback': null,
'jsonContent':null,
'jsonSubmit': function(){return true;},
'jsonComplete': function(data){return true;},
//custom processing
'customCallback': null,
//basic behavior
'useDefaultBindings': true,
'createDialog': function(){return this;},
'destroyDialog': function (){return this;},
'onSubmit': function(){return true;},
//basic look
'minWidth': 750,
'title': 'Confirm your request',
'header': '',
'footer': '',
'submitButtonsMessage': '',
'submitButtonLabel':'Submit Request',
'cancelButtonLabel': 'Cancel Request',
'submitButtonsTag': 'input',
//select all buttons
'selectAllButtonsPosition': '',
'selectAllButtonsShowAt': 0,
'selectAllButtonsTag': 'button',
'selectAllButtonLabel': 'Select All',
'selectNoneButtonLabel':'Select None',
//simple copy options
'includeSimpleCopyOption': false,
'simpleCopyLabel': 'Requesting Duplication of Material',
'simpleCopyMessage': '',
//advanced copy options
'includeAdvancedCopyOptions':false,
'advancedCopyMessage': '',
'formatLabel': 'Format',
'formatOptions': [ 'Photocopy', 'Scan (DVD/CD)', 'Scan (Electronic Delivery)' ],
'serviceLevelLabel': 'Intended Use',
'serviceLevelOptions':['Advertisement (Commercial)', 'Advertisement (PSA)', 'Educational Use', 'Government', 'Live Presentation', 'Museum Use', 'Non Profit', 'Personal Use', 'Preservation Use'],
'shippingOptionLabel': 'Shipping Option',
'shippingOptions': ['Download/FTP (User Provided)', 'Download/FTP (Institution Provided)', 'Pick up Onsite', 'Fed Ex (User Account)', 'UPS (User Account)', 'USPS (First Class)', 'USPS (Overseas)' ],
'forPublicationLabel': 'For Publication',
//notes
'includeNotes': true,
'notesMessage': 'Please include any notes that might help us identify the specific items requested or any other pertinent information:',
//scheduled date
'includeScheduledDate':true,
'scheduledDateMessage':'',
'scheduledDateLabel': 'Scheduled Date',
'userReviewLabel': 'Keep this request saved in your account for later review. It will not be sent to Libraries staff for fulfilment.',
//optional behavior
'compressRequests': false,
'compressRequestsField': 'ItemNumber',
'stripUnchecked':true,
'cleanValues': function(s){ return s.replace(/^\s*/, "").replace(/\s*$/,''); },
'cleanNotes': true,
//templates
'itemsAttachpointSelector': '.aeon_request_items',
'itemsTemplate': '<div>' +
'<% for ( var x=0; x < this.items.length; x++ ) { %>' +
'<div class="requestItem" style="clear:both">' +
'<div class="request_inputs">' +
'<input type="checkbox" name="Request" value="<%= x %>" checked="checked"/>' +
'<% for ( var y=0; y < this.items[x].fields.length; y++ ){ %>' +
'<input type="hidden" name="<%= this.items[x].fields[y].name %>_<%= x %>" value="<%= this.items[x].fields[y].value %>">' +
'<% } %>' +
'</div>' +
'<% for ( var y=0; y < this.items[x].fields.length; y++ ){ %>' +
'<% if ( this.items[x].fields[y].label ) { %>' +
'<div class="requestDesc"><span class="label"><%= this.items[x].fields[y].label %>:</span> <%= this.items[x].fields[y].value %></div>' +
'<% } %>' +
'<% } %>' +
'</div>' +
'<% } %>' +
'</div>',
'template':'<form method="POST" action="<%= this.url %>" class="aeon_request_form" target="_self" name="<%= this.AeonForm %>">' +
'<input name="AeonForm" type="hidden" value="<%= this.AeonForm %>"/>' +
'<input name="RequestType" type="hidden" value="<%= this.RequestType %>" />' +
'<input name="SubmitButton" value="Submit Request" type="hidden" />' +
'<% for (var x=0; x < this.globalFields.length; x++ ) { %>' +
'<input name="<%= this.globalFields[x].name %>" type="hidden" value="<%= this.globalFields[x].value %>" />' +
'<% } %>' +
'<% if ( this.header ) { %>' +
'<div class="aeon_request_header"><%= this.header %></div>' +
'<% } %>' +
'<% if ( this.selectAllButtonsPosition === "top" || this.selectAllButtonsPosition === "both" ) { %>' +
'<% if ( !this.selectAllButtonsShowAt || ( this.items.length >= this.selectAllButtonsShowAt ) ) { %>' +
'<div class="select_all_buttons">' +
'<<%= this.selectAllButtonsTag %> class="select_all" <%= this.selectAllButtonsTag === \'a\' ? \'href="#"\' : "" %>><%= this.selectAllButtonLabel %></<%= this.selectAllButtonsTag %>>' +
'<<%= this.selectAllButtonsTag %> class="select_none" <%= this.selectAllButtonsTag === \'a\' ? \'href="#"\' : "" %>><%= this.selectNoneButtonLabel %></<%= this.selectAllButtonsTag %>>' +
'</div>' +
'<% } %>' +
'<% } %>' +
'<div class="aeon_request_items"></div>' +
'<% if ( this.selectAllButtonsPosition === "bottom" || this.selectAllButtonsPosition === "both" ) { %>' +
'<% if ( !this.selectAllButtonsShowAt || ( this.items.length >= this.selectAllButtonsShowAt ) ) { %>' +
'<div class="select_all_buttons">' +
'<<%= this.selectAllButtonsTag %> class="select_all" <%= this.selectAllButtonsTag === \'a\' ? \'href="#"\' : "" %>><%= this.selectAllButtonLabel %></<%= this.selectAllButtonsTag %>>' +
'<<%= this.selectAllButtonsTag %> class="select_none" <%= this.selectAllButtonsTag === \'a\' ? \'href="#"\' : "" %>><%= this.selectNoneButtonLabel %></<%= this.selectAllButtonsTag %>>' +
'</div>' +
'<% } %>' +
'<% } %>' +
'<% if ( this.includeSimpleCopyOption ) { %>' +
'<div class="simple_copy_opt">' +
'<% if ( this.simpleCopyMessage ) { %>' +
'<div class="simple_copy_message message"><%= this.simpleCopyMessage %></div>' +
'<% } %>' +
'<div class="request_inputs">' +
'<input type="checkbox" class="copy_check" value="Yes"/>' +
'</div>' +
'<div class="requestDesc"><label for="aeon_request_copy"><span class="label"><%= this.simpleCopyLabel %></span></label></div>' +
'</div>' +
'<% } %>' +
'<% if ( this.includeAdvancedCopyOptions ) { %>' +
'<div class="advanced_copy_opt">' +
'<% if ( this.advancedCopyMessage ) { %>' +
'<div class="adv_copy_message message"><%= this.advancedCopyMessage %></div>' +
'<% } %>' +
'<div class="adv_copy_element">' +
'<label for="Format" class="label"><%= this.formatLabel %></label>' +
'<select name="Format" class="adv_copy_select">' +
'<% for ( var x=0; x < this.formatOptions.length; x++ ) { %>' +
'<% var o = this.formatOptions[x]; %>' +
'<% if ( typeof o === "object" ) { %>' +
'<option value="<%= o.value %>"><%= o.label %></option>'+
'<% } else { %>' +
'<option><%= o %></option>'+
'<% } %>' +
'<% } %>' +
'</select>' +
'</div>' +
'<div class="adv_copy_element">' +
'<label for="ServiceLevel" class="label"><%= this.serviceLevelLabel %></label>' +
'<select name="ServiceLevel" class="adv_copy_select">' +
'<% for ( var x=0; x < this.serviceLevelOptions.length; x++ ) { %>' +
'<% var o = this.serviceLevelOptions[x]; %>' +
'<% if ( typeof o === "object" ) { %>' +
'<option value="<%= o.value %>"><%= o.label %></option>'+
'<% } else { %>' +
'<option><%= o %></option>'+
'<% } %>' +
'<% } %>' +
'</select>' +
'</div>' +
'<div class="adv_copy_element">' +
'<label for="ShippingOption" class="label"><%= this.shippingOptionLabel %></label>' +
'<select name="ShippingOption" class="adv_copy_select">' +
'<% for ( var x=0; x < this.shippingOptions.length; x++ ) { %>' +
'<% var o = this.shippingOptions[x]; %>' +
'<% if ( typeof o === "object" ) { %>' +
'<option value="<%= o.value %>"><%= o.label %></option>'+
'<% } else { %>' +
'<option><%= o %></option>'+
'<% } %>' +
'<% } %>' +
'</select>' +
'</div>' +
'<div class="adv_copy_element">' +
'<label for="ForPublication" class="label"><%= this.forPublicationLabel %></label>' +
'<input name="ForPublication" type="checkbox" value="Yes">' +
'</div>' +
'</div>' +
'<% } %>' +
'<% if ( this.includeNotes ) { %>' +
'<div class="notes">' +
'<% if ( this.notesMessage ) { %>' +
'<label for="Notes" class="notes_message message"><%= this.notesMessage %></label><br/>' +
'<% } %>' +
'<textarea name="Notes" cols="60" rows="4"></textarea>' +
'</div>' +
'<% } %>' +
'<% if (this.includeScheduledDate) { %>' +
'<div class="scheduled_date_options">'+
'<% if ( this.scheduledDateMessage ) { %>' +
'<div class="scheduled_date_message message"><%= this.scheduledDateMessage %></div>' +
'<% } %>' +
'<div class="rev_sched_opt">' +
'<input type="radio" name="UserReview" class="schedule_opt scheduled_date_radio" value="No" checked="checked"/>' +
'</div>' +
'<div class="scheduled_date">' +
'<label for="scheduled_date_radio"><span class="label"><%= this.scheduledDateLabel %></span></label><br/>' +
'<input type="text" class="datepicker" name="ScheduledDate"/>' +
'</div>' +
'<div class="rev_sched_opt">' +
'<input type="radio" name="UserReview" value="Yes" class="schedule_opt user_review_radio"/>' +
'</div>' +
'<div class="review disabled">' +
'<label for="user_review_radio"><%= this.userReviewLabel %></label>' +
'</div>' +
'</div>' +
'<% } %>' +
'<div class="buttons">' +
'<% if ( this.submitButtonsMessage ) { %>' +
'<div class="buttonMessage message"><%= this.submitButtonsMessage %></div>' +
'<% } %>' +
'<% if ( this.submitButtonsTag === "input" ) { %>' +
'<input type="submit" value="<%= this.submitButtonLabel %>" class="dialog_submit"/>' +
'<input type="reset" value="<%= this.cancelButtonLabel %>" class="dialog_cancel"/>' +
'<% } else { %>' +
'<<%= this.submitButtonsTag %> class="dialog_submit" <%= this.submitButtonsTag === \'a\' ? \'href="#"\' : "" %>><%= this.submitButtonLabel %></<%= this.submitButtonsTag %>>' +
'<<%= this.submitButtonsTag %> class="dialog_cancel" <%= this.submitButtonsTag === \'a\' ? \'href="#"\' : "" %>><%= this.cancelButtonLabel %></<%= this.submitButtonsTag %>>' +
'<% } %>' +
'</div>' +
'<% if ( this.footer ) { %>' +
'<div class="aeon_footer"><%= this.footer %></div>' +
'<% } %>' +
'</form>'
}, options);
if ( settings.includeAdvancedCopyOptions ) {
settings.RequestType = 'Copy';
}
$(settings.submitButtonSelector).on('click.aeonRequestsDialogMain', function (e) {
e.preventDefault();
e.stopPropagation();
methods.show.apply($this, null);
});
$(this).data('aeonRequestsDialog', {
settings: settings
});
$('body').jqoteapp('<div style="display:none"><div id="<%= this.dialogId %>" title="<%= this.title %>" class="aeon_request"></div></div>',settings);
} else {
console.log( "aeonRequestsDialog already initialized" );
}
return this;
},
show : function() {
var settings = this.data('aeonRequestsDialog').settings, $this = this;
//get data from form
if ( settings.datasource === 'form' ) {
methods._processForm.apply(this,null);
methods._showDialog.apply(this,null);
}
if ( settings.datasource === 'json' ) {
if ( !settings.jsonSubmit() )
return;
$.getJSON(settings.jsonUrl, settings.jsonContent,function(data){
if ( !settings.jsonComplete(data) ) {
return;
}
var o = settings.jsonCallback(data);
if ( o ){
methods.options.apply($this,[o]);
methods._showDialog.apply($this,null);
}
});
}
if ( settings.datasource === 'custom') {
var o = settings.customCallback();
if ( o ){
methods.options.apply($this,[o]);
methods._showDialog.apply($this,null);
}
}
},
_showDialog: function(){
var settings = this.data('aeonRequestsDialog').settings,
$this = this,
$dialog = $('#'+ settings.dialogId),
opts = {
modal:true,
autoOpen:false,
close: function(){
if ( settings.useDefaultBindings ) {
methods._defaultDestroyDialog.apply($this,null);
}
settings.destroyDialog();
$(window).off('.aeonRequestsDialog'+'#' + settings.dialogId);
$dialog.dialog('destroy');
$dialog.html('');
}
},
f = [ 'height','width'],
f2 = [ 'min', 'max' ];
$dialog.jqotesub(settings.template, settings);
$('#' + settings.dialogId + " " + settings.itemsAttachpointSelector).jqotesub(settings.itemsTemplate,settings);
//setup dialog
for (var x=0;x < 2; x++) {
if (settings[f[x]]) {
opts[f[x]] = settings[f[x]];
continue;
}
for (var y=0;y<2;y++) {
var s = f2[y] + f[x].charAt(0).toUpperCase() + f[x].slice(1);
if (settings[s]) {
opts[s] = settings[s];
}
}
}
$dialog.dialog(opts);
if ( settings.useDefaultBindings ) {
methods._defaultCreateDialog.apply(this,null);
}
settings.createDialog();
$dialog.dialog('open');
return this;
},
_defaultCreateDialog: function (){
var $this = this;
var settings = this.data('aeonRequestsDialog').settings;
var idSelector = '#' + settings.dialogId;
$( idSelector + ' .datepicker').datepicker({minDate:0}).val($.datepicker.formatDate('mm/dd/yy',new Date()));
$(idSelector + ' .select_all').on( 'click.aeonRequestsDialog' + idSelector, function(e){
e.preventDefault();
e.stopPropagation();
$(idSelector + ' ' + settings.requestsSelector).prop('checked',true);
});
$(idSelector + ' .select_none').on( 'click.aeonRequestsDialog' + idSelector, function(e){
e.preventDefault();
e.stopPropagation();
$(idSelector + ' ' + settings.requestsSelector).prop('checked',false);
});
if ( settings.includeSimpleCopyOption ) {
$(idSelector + ' .copy_check').on( 'change.aeonRequestsDialog' + idSelector, function(){
if ( this.checked ) {
$( idSelector + ' input[name="RequestType"]').val('Copy');
} else {
$( idSelector + ' input[name="RequestType"]').val('Loan');
}
});
}
if ( settings.includeScheduledDate ) {
$( idSelector + ' .schedule_opt').on( 'change.aeonRequestsDialog' + idSelector, function() {
if ( this.checked && this.value === 'Yes' ) {
$(idSelector + ' .datepicker').prop('disabled','disabled');
$(idSelector + ' .scheduled_date').addClass('disabled');
$(idSelector + ' .review').removeClass('disabled');
} else {
$(idSelector + ' .datepicker').prop('disabled','');
$(idSelector + ' .scheduled_date').removeClass('disabled');
$(idSelector + ' .review').addClass('disabled');
}
});
}
$(idSelector + ' .dialog_submit').on('click.aeonRequestsDialog' + idSelector,function(e){
e.preventDefault();
e.stopPropagation();
if ( $(idSelector+' ' + settings.requestsSelector + ':checked').length == 0 ) {
return;
}
if ( !settings.onSubmit() ) {
return;
}
$('div.ui-widget-overlay').remove();
$('div.ui-dialog').css('display','none');
if ( settings.stripUnchecked ) {
methods._stripUnchecked.apply($this,null);
}
if ( settings.compressRequests ) {
methods._compressRequests.apply($this,null);
}
if ( settings.includeNotes && settings.cleanNotes ){
methods._cleanNotes.apply($this,null);
}
$(idSelector+ ' .aeon_request_form').submit();
});
$( idSelector + ' .dialog_cancel').on('click.aeonRequestsDialog' + idSelector, function(){
$(idSelector).dialog('close');
});
},
_defaultDestroyDialog: function (){
var settings = this.data('aeonRequestsDialog').settings;
$('#' + settings.dialogId + ' .datepicker').datepicker('destroy');
$(window).off('.aeonRequestsDialog#'+settings.dialogId);
},
'_processForm': function (){
var settings = this.data('aeonRequestsDialog').settings;
settings.items = [];
$(settings.requestsSelector + ':checked').each(function(){
var id = $(this).val();
var i = { 'fields': [] };
for (var x=0;x<settings.itemFields.length;x++) {
var f = {
'name':settings.itemFields[x].name,
'label':settings.itemFields[x].label,
'value': settings.cleanValues(document.forms[settings.form][settings.itemFields[x].name + '_' + id ].value )
};
i.fields.push(f);
}
settings.items.push(i);
});
for( var x=0; x<settings.globalFields.length; x++){
settings.globalFields[x].value = settings.cleanValues( document.forms[settings.form][settings.globalFields[x].name].value );
}
this.data('aeonRequestsDialog', { settings: settings });
},
_compressRequests: function(){
var settings = this.data('aeonRequestsDialog').settings;
var codes = {};
var idSelector = '#'+settings.dialogId;
var fieldName = settings.compressRequestsField;
var requestsSelector = idSelector+' ' + settings.requestsSelector + ':checked';
var requests = $(requestsSelector);
var newReqNum = requests.length;
requests.each( function(){
var requestNumber = $(this).val();
var collapseFieldValue = $(idSelector + ' input[name="'+fieldName + '_' + requestNumber +'"]').val();
if ( collapseFieldValue ){
if ( !codes[collapseFieldValue] ) {
codes[collapseFieldValue] = new Array();
}
codes[collapseFieldValue].push(requestNumber);
}
});
for (var code in codes) {
var requestNumbers = codes[code];
if ( requestNumbers.length < 2 ) {
continue;
}
var newRequest = {};
for ( var x=0;x < settings.itemFields.length;x++) {
var field = settings.itemFields[x].name;
for (var y=0;y < requestNumbers.length; y++) {
var key = requestNumbers[y];
var oldField = $(idSelector + ' input[name="'+field + '_' + key +'"]');
if (!oldField) {
continue;
}
var oldVal = oldField.val();
if (!newRequest[field]) {
newRequest[field] = oldVal;
} else if ( newRequest[field] != oldVal) {
newRequest[field] += "; " + oldVal;
}
oldField.remove();
$('input[name="Request"][value="' + key + '"]').remove();
}
}
$('<input/>').prop('type','hidden').prop('name','Request').val(newReqNum).appendTo(idSelector+ ' .aeon_request_form' );
for ( var field in newRequest ) {
$('<input/>').prop('type','hidden').prop('name',field + '_' + newReqNum).val(newRequest[field]).appendTo(idSelector+ ' .aeon_request_form' );
}
newReqNum++;
}
},
_stripUnchecked: function(){
var settings = this.data('aeonRequestsDialog').settings;
var idSelector = '#' + settings.dialogId;
var uncheckedSelector = idSelector + ' ' + settings.requestsSelector + ':not(:checked)';
$(uncheckedSelector).each( function(){
$(idSelector + ' input[name$="_' + $(this).val() +'"]').remove();
});
},
_cleanNotes: function(){
var settings = this.data('aeonRequestsDialog').settings;
var notes = $('#'+settings.dialogId + ' textarea[name="Notes"]');
var s = notes.val();
s = s.replace(/\n/g, ' ' );
notes.val(s);
},
options: function(){
var settings = this.data('aeonRequestsDialog').settings;
if (arguments.length === 0) {
return settings;
}
else if (arguments.length === 1) {
if (typeof arguments[0] === "object" ) {
settings = $.extend(settings,arguments[0]);
}
else if (typeof arguments[0] === "string" ) {
if ( undefined === settings[arguments[0]] ) {
console.log("Unknown key sent to arguments.");
return null;
}
return settings[arguments[0]];
}
else {
console.log("Argument to options must be of type Object or String");
return null;
}
}
else if ( arguments.length === 2) {
settings[arguments[0]] = arguments[1];
}
else {
console.log("Illegal number of arguments sent to options.");
return null;
}
this.data('aeonRequestsDialog', {settings:settings});
return settings;
},
destroy : function() {
var data = this.data('aeonRequestsDialog');
$(window).off('.aeonRequestsDialogMain');
$this.removeData('aeonRequestsDialog');
return this;
}
};
$.fn.aeonRequestsDialog = function( method ) {
if ( methods[method] ) {
return methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ));
} else if ( typeof method === 'object' || ! method ) {
return methods.init.apply( this, arguments );
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.aeonRequestDialog' );
return null;
}
};
})( jQuery );