-
Notifications
You must be signed in to change notification settings - Fork 439
/
NotesHandler.js
133 lines (108 loc) · 3.52 KB
/
NotesHandler.js
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
/**
* @file js/controllers/informationCenter/NotesHandler.js
*
* Copyright (c) 2000-2013 John Willinsky
* Distributed under the GNU GPL v2. For full terms see the file docs/COPYING.
*
* @class NotesHandler
* @ingroup js_controllers_informationCenter
*
* @brief Information center "notes" tab handler.
*/
(function($) {
/**
* @constructor
*
* @extends $.pkp.classes.Handler
*
* @param {jQueryObject} $notesDiv A wrapped HTML element that
* represents the "notes" interface element.
* @param {Object} options Tabbed modal options.
*/
$.pkp.controllers.informationCenter.NotesHandler =
function($notesDiv, options) {
this.parent($notesDiv, options);
// Store the list fetch URLs for later
this.fetchNotesUrl_ = options.fetchNotesUrl;
this.fetchPastNotesUrl_ = options.fetchPastNotesUrl;
// Bind for changes in the note list (e.g. new note or delete)
this.bind('formSubmitted', this.handleRefreshNoteList);
// Load a list of the current notes.
this.loadPastNoteList_();
this.loadNoteList_();
};
$.pkp.classes.Helper.inherits(
$.pkp.controllers.informationCenter.NotesHandler,
$.pkp.classes.Handler
);
//
// Private properties
//
/**
* The URL to be called to fetch a list of notes.
* @private
* @type {string}
*/
$.pkp.controllers.informationCenter.NotesHandler.
prototype.fetchNotesUrl_ = '';
/**
* The URL to be called to fetch a list of prior notes.
* @private
* @type {string}
*/
$.pkp.controllers.informationCenter.NotesHandler.
prototype.fetchPastNotesUrl_ = '';
//
// Public methods
//
/**
* Handle the "note added" event triggered by the
* note form whenever a new note is added.
*
* @param {$.pkp.controllers.form.AjaxFormHandler} callingForm The form
* that triggered the event.
* @param {Event} event The upload event.
*/
$.pkp.controllers.informationCenter.NotesHandler.
prototype.handleRefreshNoteList = function(callingForm, event) {
$(callingForm).find('[id^="newNote"]').val('');
this.loadNoteList_();
};
//
// Private methods
//
$.pkp.controllers.informationCenter.NotesHandler.prototype.
loadNoteList_ = function() {
$.get(this.fetchNotesUrl_, this.callbackWrapper(this.setNoteList_), 'json');
};
$.pkp.controllers.informationCenter.NotesHandler.prototype.
setNoteList_ = function(formElement, jsonData) {
var processedJsonData = this.handleJson(jsonData);
$('#notesList').replaceWith(processedJsonData.content);
this.getHtmlElement().find('.showMore, .showLess').
bind('click', this.switchViz);
// Initialize an accordion for the "past notes" list, if it's
// available (e.g. for a file information center).
if (!$('#notesAccordion').hasClass('ui-accordion')) {
$('#notesAccordion').accordion({ clearStyle: true });
} else {
// this is a refresh. Since the accordion exists, we must destroy
// and then recreate it or the content looks unstyled.
$('#notesAccordion').accordion('destroy').accordion({ clearStyle: true });
}
};
$.pkp.controllers.informationCenter.NotesHandler.prototype.
loadPastNoteList_ = function() {
// Only attempt to load the past note list if it's in the UI
if ($('#pastNotesList').length) {
$.get(this.fetchPastNotesUrl_,
this.callbackWrapper(this.setPastNoteList_), 'json');
}
};
$.pkp.controllers.informationCenter.NotesHandler.prototype.
setPastNoteList_ = function(formElement, jsonData) {
var processedJsonData = this.handleJson(jsonData);
$('#pastNotesList').replaceWith(jsonData.content);
};
/** @param {jQuery} $ jQuery closure. */
}(jQuery));