first commit
This commit is contained in:
@@ -0,0 +1,120 @@
|
||||
/**
|
||||
* @defgroup js_controllers_grid_queries
|
||||
*/
|
||||
/**
|
||||
* @file js/controllers/grid/queries/QueryFormHandler.js
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class ReadQueryHandler
|
||||
* @ingroup js_controllers_grid_queries
|
||||
*
|
||||
* @brief Handler for a query form modal
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
/** @type {Object} */
|
||||
$.pkp.controllers.grid.queries =
|
||||
$.pkp.controllers.grid.queries || {};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @extends $.pkp.controllers.form.CancelActionAjaxFormHandler
|
||||
*
|
||||
* @param {jQueryObject} $form The query form element
|
||||
* @param {Object} options non-default Dialog options
|
||||
* to be passed into the dialog widget.
|
||||
*
|
||||
* Options are:
|
||||
* - all options documented for the CancelActionAjaxFormHandler.
|
||||
* - templateUrl: The URL to retrieve templates from.
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.QueryFormHandler =
|
||||
function($form, options) {
|
||||
this.parent($form, options);
|
||||
|
||||
// Set the URL to retrieve templates from.
|
||||
if (options.templateUrl) {
|
||||
this.templateUrl_ = options.templateUrl;
|
||||
}
|
||||
|
||||
// Attach form elements events.
|
||||
$form.find('#template').change(
|
||||
this.callbackWrapper(this.selectTemplateHandler_));
|
||||
};
|
||||
$.pkp.classes.Helper.inherits($.pkp.controllers.grid.queries.
|
||||
QueryFormHandler, $.pkp.controllers.form.CancelActionAjaxFormHandler);
|
||||
|
||||
|
||||
//
|
||||
// Private properties
|
||||
//
|
||||
/**
|
||||
* The URL to use to retrieve template bodies
|
||||
* @private
|
||||
* @type {string?}
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.
|
||||
QueryFormHandler.prototype.templateUrl_ = null;
|
||||
|
||||
|
||||
//
|
||||
// Private methods
|
||||
//
|
||||
/**
|
||||
* Respond to an "item selected" call by triggering a published event.
|
||||
*
|
||||
* @param {HTMLElement} sourceElement The element that
|
||||
* issued the event.
|
||||
* @param {Event} event The triggering event.
|
||||
* @private
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.
|
||||
QueryFormHandler.prototype.selectTemplateHandler_ =
|
||||
function(sourceElement, event) {
|
||||
var $form = this.getHtmlElement(),
|
||||
template = $form.find('[name="template"]');
|
||||
$.post(this.templateUrl_, template.serialize(),
|
||||
this.callbackWrapper(this.updateTemplate), 'json');
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Private methods
|
||||
//
|
||||
/**
|
||||
* Internal callback to replace the textarea with the contents of the
|
||||
* template body.
|
||||
*
|
||||
* @param {HTMLElement} formElement The wrapped HTML form.
|
||||
* @param {Object} jsonData The data returned from the server.
|
||||
* @return {boolean} The response status.
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.
|
||||
QueryFormHandler.prototype.updateTemplate =
|
||||
function(formElement, jsonData) {
|
||||
|
||||
var $form = this.getHtmlElement(),
|
||||
processedJsonData = this.handleJson(jsonData),
|
||||
jsonDataContent =
|
||||
/** @type {{variables: Object, body: string}} */ (jsonData.content),
|
||||
$textarea = $form.find('textarea[name="comment"]'),
|
||||
editor =
|
||||
tinyMCE.EditorManager.get(/** @type {string} */ ($textarea.attr('id')));
|
||||
|
||||
if (jsonDataContent.variables) {
|
||||
$textarea.attr('data-variables', JSON.stringify(jsonDataContent.variables));
|
||||
}
|
||||
editor.setContent(jsonDataContent.body);
|
||||
$form.find('[name="subject"]').val(jsonDataContent.subject);
|
||||
|
||||
return processedJsonData.status;
|
||||
};
|
||||
|
||||
}(jQuery));
|
||||
@@ -0,0 +1,167 @@
|
||||
/**
|
||||
* @defgroup js_controllers_grid_queries
|
||||
*/
|
||||
/**
|
||||
* @file js/controllers/grid/queries/ReadQueryHandler.js
|
||||
*
|
||||
* Copyright (c) 2014-2021 Simon Fraser University
|
||||
* Copyright (c) 2000-2021 John Willinsky
|
||||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
|
||||
*
|
||||
* @class ReadQueryHandler
|
||||
* @ingroup js_controllers_grid_queries
|
||||
*
|
||||
* @brief Handler for a "read query" modal
|
||||
*
|
||||
*/
|
||||
(function($) {
|
||||
|
||||
/** @type {Object} */
|
||||
$.pkp.controllers.grid.queries =
|
||||
$.pkp.controllers.grid.queries || { };
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
*
|
||||
* @extends $.pkp.classes.Handler
|
||||
*
|
||||
* @param {jQueryObject} $containerElement The HTML element encapsulating
|
||||
* the carousel container.
|
||||
* @param {Object} options Handler options.
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.ReadQueryHandler =
|
||||
function($containerElement, options) {
|
||||
|
||||
this.fetchNoteFormUrl_ = options.fetchNoteFormUrl;
|
||||
this.fetchParticipantsListUrl_ = options.fetchParticipantsListUrl;
|
||||
|
||||
$containerElement.find('.openNoteForm a').click(
|
||||
this.callbackWrapper(this.showNoteFormHandler_));
|
||||
|
||||
$containerElement.bind('dataChanged',
|
||||
this.callbackWrapper(this.reloadParticipantsList_));
|
||||
|
||||
$containerElement.bind('user-left-discussion', function() {
|
||||
$containerElement.parent().trigger('modalFinished');
|
||||
});
|
||||
|
||||
this.loadParticipantsList();
|
||||
};
|
||||
$.pkp.classes.Helper.inherits(
|
||||
$.pkp.controllers.grid.queries.ReadQueryHandler,
|
||||
$.pkp.classes.Handler);
|
||||
|
||||
|
||||
//
|
||||
// Private properties
|
||||
//
|
||||
/**
|
||||
* The URL to be called to fetch a new note form for a query.
|
||||
* @private
|
||||
* @type {string?}
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.ReadQueryHandler.
|
||||
prototype.fetchNoteFormUrl_ = null;
|
||||
|
||||
|
||||
/**
|
||||
* The URL to be called to fetch a list of participants.
|
||||
* @private
|
||||
* @type {string?}
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.ReadQueryHandler.
|
||||
prototype.fetchParticipantsListUrl_ = null;
|
||||
|
||||
|
||||
//
|
||||
// Public methods
|
||||
//
|
||||
/**
|
||||
* Load the participants list.
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.ReadQueryHandler.prototype.
|
||||
loadParticipantsList = function() {
|
||||
$.get(this.fetchParticipantsListUrl_,
|
||||
this.callbackWrapper(this.showFetchedParticipantsList_), 'json');
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// Private methods
|
||||
//
|
||||
/**
|
||||
* Event handler that is called when the "new note" button is clicked.
|
||||
* @param {HTMLElement} element The checkbox input element.
|
||||
* @private
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.ReadQueryHandler.prototype.
|
||||
showNoteFormHandler_ = function(element) {
|
||||
$(element).parents('.queryEditButtons').addClass('is_loading');
|
||||
$.get(this.fetchNoteFormUrl_,
|
||||
this.callbackWrapper(this.showFetchedNoteForm_), 'json');
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Event handler that is called when the new note form is ready.
|
||||
* @param {Object} ajaxContext The AJAX request context.
|
||||
* @param {Object} jsonData A parsed JSON response object.
|
||||
* @private
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.ReadQueryHandler.prototype.
|
||||
showFetchedNoteForm_ = function(ajaxContext, jsonData) {
|
||||
|
||||
var processedJsonData = this.handleJson(jsonData),
|
||||
$noteFormContainer = $('#newNotePlaceholder', this.getHtmlElement()),
|
||||
$queryEditButtons = $('.queryEditButtons.is_loading',
|
||||
this.getHtmlElement());
|
||||
|
||||
this.unbindPartial($queryEditButtons);
|
||||
$queryEditButtons.remove();
|
||||
this.unbindPartial($noteFormContainer);
|
||||
$noteFormContainer.html(processedJsonData.content);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Event handler that is called when the participants list fetch is complete.
|
||||
* @param {Object} ajaxContext The AJAX request context.
|
||||
* @param {Object} jsonData A parsed JSON response object.
|
||||
* @private
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.ReadQueryHandler.prototype.
|
||||
showFetchedParticipantsList_ = function(ajaxContext, jsonData) {
|
||||
|
||||
var processedJsonData = this.handleJson(jsonData),
|
||||
$participantsListContainer = $('#participantsListPlaceholder',
|
||||
this.getHtmlElement()),
|
||||
$leaveQueryButton = $('.leaveQueryForm', this.getHtmlElement());
|
||||
|
||||
if (processedJsonData.showLeaveQueryButton) {
|
||||
$leaveQueryButton.show();
|
||||
} else {
|
||||
$leaveQueryButton.hide();
|
||||
}
|
||||
|
||||
this.unbindPartial($participantsListContainer);
|
||||
$participantsListContainer.children().remove();
|
||||
$participantsListContainer.append(processedJsonData.content);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Handler to update the participants list on change.
|
||||
* @param {HTMLElement} sourceElement The element that issued the
|
||||
* "dataChanged" event.
|
||||
* @param {Event} event The "dataChanged" event.
|
||||
* @param {HTMLElement} triggerElement The element that triggered
|
||||
* the "dataChanged" event.
|
||||
* @private
|
||||
*/
|
||||
$.pkp.controllers.grid.queries.ReadQueryHandler.prototype.
|
||||
reloadParticipantsList_ = function(sourceElement, event, triggerElement) {
|
||||
this.loadParticipantsList();
|
||||
};
|
||||
}(jQuery));
|
||||
Reference in New Issue
Block a user