first commit

This commit is contained in:
CHIEFSOFT\ameye
2024-06-08 17:09:23 -04:00
commit df3a033196
17887 changed files with 8637778 additions and 0 deletions
@@ -0,0 +1,79 @@
/**
* @file js/classes/linkAction/AjaxRequest.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 AjaxRequest
* @ingroup js_classes_linkAction
*
* @brief AJAX link action request.
*/
(function($) {
/**
* @constructor
*
* @extends $.pkp.classes.linkAction.LinkActionRequest
*
* @param {jQueryObject} $linkActionElement The element the link
* action was attached to.
* @param {{
* requestType: string,
* data: PlainObject
* }} options Configuration of the link action
* request.
*/
$.pkp.classes.linkAction.AjaxRequest =
function($linkActionElement, options) {
this.parent($linkActionElement, options);
};
$.pkp.classes.Helper.inherits(
$.pkp.classes.linkAction.AjaxRequest,
$.pkp.classes.linkAction.LinkActionRequest);
//
// Public methods
//
/**
* @inheritDoc
*/
$.pkp.classes.linkAction.AjaxRequest.prototype.activate =
function(element, event) {
var returnValue = /** @type {boolean} */ (
this.parent('activate', element, event)),
options = this.getOptions(),
responseHandler = $.pkp.classes.Helper.curry(
this.handleResponse, this);
switch (options.requestType) {
case 'get':
$.getJSON(options.url, options.data, responseHandler);
break;
case 'post':
$.post(options.url, options.data, responseHandler, 'json');
break;
}
return returnValue;
};
/**
* Handle the AJAX response.
* @param {Object} jsonData The data returned by the server.
*/
$.pkp.classes.linkAction.AjaxRequest.prototype.handleResponse =
function(jsonData) {
var $linkActionHandler = this.getLinkActionElement().data('pkp.handler');
$linkActionHandler.handleJson(jsonData);
this.finish();
};
}(jQuery));
@@ -0,0 +1,57 @@
/**
* @file js/classes/linkAction/EventAction.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 EventAction
* @ingroup js_classes_linkAction
*
* @brief A simple action request that triggers a Javascript event.
*/
(function($) {
/**
* @constructor
*
* @extends $.pkp.classes.linkAction.LinkActionRequest
*
* @param {jQueryObject} $linkActionElement The element the link
* action was attached to.
* @param {Object} options Configuration of the link action
* request.
*/
$.pkp.classes.linkAction.EventAction =
function($linkActionElement, options) {
this.parent($linkActionElement, options);
};
$.pkp.classes.Helper.inherits(
$.pkp.classes.linkAction.EventAction,
$.pkp.classes.linkAction.LinkActionRequest);
//
// Public methods
//
/**
* @inheritDoc
*/
$.pkp.classes.linkAction.EventAction.prototype.activate =
function(element, event) {
$(this.options.target).trigger(this.options.event,
/** @type {Array} */ (this.options));
return /** @type {boolean} */ (this.parent('activate', element, event));
};
/**
* Determine whether or not the link action should be debounced.
* @return {boolean} Whether or not to debounce the link action.
*/
$.pkp.classes.linkAction.EventAction.prototype.shouldDebounce =
function() {
return false;
};
}(jQuery));
@@ -0,0 +1,157 @@
/**
* @defgroup js_classes_linkAction
*/
/**
* @file js/classes/linkAction/LinkActionRequest.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 LinkActionRequest
* @ingroup js_classes_linkAction
*
* @brief Base class for all link action requests.
*/
(function($) {
/** @type {Object} */
$.pkp.classes.linkAction = $.pkp.classes.linkAction || {};
/**
* @constructor
*
* @extends $.pkp.classes.ObjectProxy
*
* @param {jQueryObject} $linkActionElement The element the link
* action was attached to.
* @param {Object} options Configuration of the link action
* request.
*/
$.pkp.classes.linkAction.LinkActionRequest =
function($linkActionElement, options) {
// Save the reference to the link action element.
this.$linkActionElement = $linkActionElement;
// Save the link action request options.
this.options = options;
// If the link action element is an actual link
// and we find a URL in the options then set the
// link of the link action for better documentation
// and easier debugging in the DOM and for other
// JS to easily access the target if required.
if ($linkActionElement.is('a') && options.url) {
$linkActionElement.attr('href', options.url);
}
};
//
// Protected properties
//
/**
* The element the link action was attached to.
* @protected
* @type {jQueryObject}
*/
$.pkp.classes.linkAction.LinkActionRequest.prototype.
$linkActionElement = null;
/**
* The link action request options.
* @protected
* @type {Object}
*/
$.pkp.classes.linkAction.LinkActionRequest.prototype.options = null;
//
// Public methods
//
/**
* Callback that will be bound to the link action element.
* @param {HTMLElement} element The element that triggered the link
* action activation event.
* @param {Event} event The event that activated the link action.
* @return {boolean} Should return false to stop event propagation.
*/
$.pkp.classes.linkAction.LinkActionRequest.prototype.activate =
function(element, event) {
this.getLinkActionElement().trigger('actionStart');
return false;
};
/**
* Callback that will be bound to the 'action finished' event of the
* link action.
*
* @return {boolean} Should return false to stop event propagation.
*/
$.pkp.classes.linkAction.LinkActionRequest.prototype.finish =
function() {
// Execute the finish callback if there is one.
if (this.options.finishCallback) {
this.options.finishCallback();
}
this.getLinkActionElement().trigger('actionStop');
return false;
};
/**
* Get the link action request url.
* @return {?string} The link action request url.
*/
$.pkp.classes.linkAction.LinkActionRequest.prototype.getUrl =
function() {
if (this.options.url) {
return this.options.url;
} else {
return null;
}
};
//
// Protected methods
//
/**
* Retrieve the link action request options.
* @return {Object} The link action request options.
*/
$.pkp.classes.linkAction.LinkActionRequest.prototype.getOptions = function() {
return this.options;
};
/**
* Retrieve the element the link action was attached to.
* @return {jQueryObject} The element the link action was attached to.
*/
$.pkp.classes.linkAction.LinkActionRequest.prototype.
getLinkActionElement = function() {
return this.$linkActionElement;
};
/**
* Determine whether or not the link action should be debounced.
* @return {boolean} Whether or not to debounce the link action.
*/
$.pkp.classes.linkAction.LinkActionRequest.prototype.
shouldDebounce = function() {
return true;
};
}(jQuery));
@@ -0,0 +1,132 @@
/**
* @file js/classes/linkAction/ModalRequest.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 ModalRequest
* @ingroup js_classes_linkAction
*
* @brief Modal link action request.
*/
(function($) {
/**
* @constructor
*
* @extends $.pkp.classes.linkAction.LinkActionRequest
*
* @param {jQueryObject} $linkActionElement The element the link
* action was attached to.
* @param {{
* modalHandler: Object
* }} options Configuration of the link action
* request.
*/
$.pkp.classes.linkAction.ModalRequest =
function($linkActionElement, options) {
this.parent($linkActionElement, options);
};
$.pkp.classes.Helper.inherits(
$.pkp.classes.linkAction.ModalRequest,
$.pkp.classes.linkAction.LinkActionRequest);
//
// Private properties
//
/**
* A pointer to the modal HTML element.
* @private
* @type {jQueryObject}
*/
$.pkp.classes.linkAction.ModalRequest.prototype.$modal_ = null;
//
// Public methods
//
/**
* @inheritDoc
*/
$.pkp.classes.linkAction.ModalRequest.prototype.activate =
function(element, event) {
// If there is no title then try to retrieve a title
// from the calling element's text.
var modalOptions = this.getOptions(),
$handledElement = this.getLinkActionElement(),
title = $handledElement.text(),
uuid,
$linkActionElement,
linkActionHandler,
handlerOptions,
modalHandler;
if (modalOptions.title === undefined) {
if (title === '') {
// Try to retrieve a title from the link action element's
// title attribute.
title = $handledElement.attr('title');
}
modalOptions.title = title;
}
// Generate a unique ID.
uuid = $.pkp.classes.Helper.uuid();
// Instantiate the modal.
if (!modalOptions.modalHandler) {
throw new Error(['The "modalHandler" setting is required ',
'in a ModalRequest'].join(''));
}
// Make sure that all events triggered on the modal will be
// forwarded to the link action. This is necessary because the
// modal has to be created outside the regular DOM.
$linkActionElement = /** @type {jQueryObject} */ (
this.getLinkActionElement());
linkActionHandler = $.pkp.classes.Handler.getHandler($linkActionElement);
handlerOptions = $.extend(true,
{eventBridge: linkActionHandler.getStaticId()}, modalOptions);
this.$modal_ = $(
'<div id="' + uuid + '" ' +
'class="pkp_modal pkpModalWrapper" tabindex="-1"></div>')
.pkpHandler(modalOptions.modalHandler, handlerOptions);
// Subscribe to the modal handler's 'removed' event so that
// we can clean up.
modalHandler = $.pkp.classes.Handler.getHandler(this.$modal_);
modalHandler.bind('pkpRemoveHandler',
$.pkp.classes.Helper.curry(this.finish, this));
return /** @type {boolean} */ (this.parent('activate', element, event));
};
/**
* @inheritDoc
*/
$.pkp.classes.linkAction.ModalRequest.prototype.finish =
function() {
// A workaround for a bug in IE9-11 (and maybe others), whereby restoring
// the focus to the New Review Round tab causes the modal to be opened
// again. This hack effects accessibility and should be removed if/when we
// move away from jQueryUI tabs.
// See: https://github.com/pkp/pkp-lib/issues/2703
if (this.$linkActionElement.attr('id')
.indexOf('newRoundTabContainer') !== 0) {
// Put the focus back on the linkAction which launched the modal
this.$linkActionElement.focus();
}
this.$modal_.remove();
return /** @type {boolean} */ (this.parent('finish'));
};
}(jQuery));
@@ -0,0 +1,59 @@
/**
* @file js/classes/linkAction/NullAction.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 NullAction
* @ingroup js_classes_linkAction
*
* @brief A simple action request that doesn't.
*/
(function($) {
/**
* @constructor
*
* @extends $.pkp.classes.linkAction.LinkActionRequest
*
* @param {jQueryObject} $linkActionElement The element the link
* action was attached to.
* @param {Object} options Configuration of the link action
* request.
*/
$.pkp.classes.linkAction.NullAction =
function($linkActionElement, options) {
this.parent($linkActionElement, options);
};
$.pkp.classes.Helper.inherits(
$.pkp.classes.linkAction.NullAction,
$.pkp.classes.linkAction.LinkActionRequest);
//
// Public methods
//
/**
* @inheritDoc
*/
$.pkp.classes.linkAction.NullAction.prototype.activate =
function(element, event) {
return /** @type {boolean} */ (this.parent('activate', element, event));
};
/**
* Determine whether or not the link action should be debounced.
* @return {boolean} Whether or not to debounce the link action.
*/
$.pkp.classes.linkAction.NullAction.prototype.shouldDebounce =
function() {
return false;
};
}(jQuery));
@@ -0,0 +1,52 @@
/**
* @file js/classes/linkAction/OpenWindowRequest.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 OpenWindowRequest
* @ingroup js_classes_linkAction
*
* @brief A simple action request that will follow the given URL.
*/
(function($) {
/**
* @constructor
*
* @extends $.pkp.classes.linkAction.LinkActionRequest
*
* @param {jQueryObject} $linkActionElement The element the link
* action was attached to.
* @param {Object} options Configuration of the link action
* request.
*/
$.pkp.classes.linkAction.OpenWindowRequest =
function($linkActionElement, options) {
this.parent($linkActionElement, options);
};
$.pkp.classes.Helper.inherits(
$.pkp.classes.linkAction.OpenWindowRequest,
$.pkp.classes.linkAction.LinkActionRequest);
//
// Public methods
//
/**
* @inheritDoc
*/
$.pkp.classes.linkAction.OpenWindowRequest.prototype.activate =
function(element, event) {
var options = this.getOptions();
window.open(options.url);
return /** @type {boolean} */ (this.parent('activate', element, event));
};
}(jQuery));
@@ -0,0 +1,132 @@
/**
* @file js/classes/linkAction/PostAndRedirectRequest.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 PostAndRedirectRequest
* @ingroup js_classes_linkAction
*
* @brief An action request that will post data and then redirect, using two
* different urls. For both requests, it will post the passed data. If none is
* passed, then it will post nothing. You can provide a js event response for
* the first post request and it will be handled.
*/
(function($) {
/**
* @constructor
*
* @extends $.pkp.classes.linkAction.LinkActionRequest
*
* @param {jQueryObject} $linkActionElement The element the link
* action was attached to.
* @param {Object} options Configuration of the link action
* request.
*/
$.pkp.classes.linkAction.PostAndRedirectRequest =
function($linkActionElement, options) {
this.parent($linkActionElement, options);
};
$.pkp.classes.Helper.inherits(
$.pkp.classes.linkAction.PostAndRedirectRequest,
$.pkp.classes.linkAction.LinkActionRequest);
//
// Private properties
//
/**
* Post request response data.
* @private
* @type {?Object}
*/
$.pkp.classes.linkAction.PostAndRedirectRequest.prototype.
postJsonData_ = null;
//
// Public methods
//
/**
* @inheritDoc
*/
$.pkp.classes.linkAction.PostAndRedirectRequest.prototype.activate =
function(element, event) {
var returner = this.parent('activate', element, event),
options = this.getOptions(),
// Create a response handler for the first request (post).
responseHandler = $.pkp.classes.Helper.curry(
this.handleResponse_, this),
finishCallback;
// Post.
$.post(/** @type {{postUrl: string}} */ (options).postUrl,
responseHandler, 'json');
return /** @type {boolean} */ (returner);
};
//
// Private helper methods.
//
/**
* Callback to be called after a timeout.
* @private
*/
$.pkp.classes.linkAction.PostAndRedirectRequest.prototype.finishCallback_ =
function() {
var $linkActionElement = this.getLinkActionElement(),
// Get the link action handler to handle the json response.
linkActionHandler = $.pkp.classes.Handler.getHandler($linkActionElement);
this.finish();
linkActionHandler.handleJson(this.postJsonData_);
};
/**
* The post data response handler.
* @param {Object} jsonData A parsed JSON response object.
* @private
*/
$.pkp.classes.linkAction.PostAndRedirectRequest.prototype.handleResponse_ =
function(jsonData) {
var options = this.getOptions(), timer = null, finishCallback = null;
// Save return data to be handled at the finish callback. If
// the redirect action loads another page, then the interface
// will be updated anyway and any events that could be triggered
// by the post response will be useless, so that's ok that the
// finish callback is not called in that case, and that the post
// json answer is never handled.
// If a new page is not loaded, then we have to wait for the redirect
// action to start (probably a file download) and only then handle the post
// answer, avoiding triggering events that could replace the current link
// action element before the redirect request starts.
// In a download action, it avoids the activation of the download link
// action before the download triggered by the first click starts.
this.postJsonData_ = jsonData;
// Redirect, making sure there is no ajax request in progress,
// to avoid stoping them.
timer = setInterval(function() {
if ($.active == 0) {
clearInterval(timer);
window.location = /** @type {{url: string}} */ (options).url;
}
},100);
// When it's a download action, try to avoid double execution.
// Not ideal, see issue #247.
finishCallback = $.pkp.classes.Helper.curry(
this.finishCallback_, this);
setTimeout(finishCallback, 2000);
};
}(jQuery));
@@ -0,0 +1,53 @@
/**
* @file js/classes/linkAction/RedirectRequest.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 RedirectRequest
* @ingroup js_classes_linkAction
*
* @brief A simple action request that will follow the given URL.
*/
(function($) {
/**
* @constructor
*
* @extends $.pkp.classes.linkAction.LinkActionRequest
*
* @param {jQueryObject} $linkActionElement The element the link
* action was attached to.
* @param {Object} options Configuration of the link action
* request.
*/
$.pkp.classes.linkAction.RedirectRequest =
function($linkActionElement, options) {
this.parent($linkActionElement, options);
};
$.pkp.classes.Helper.inherits(
$.pkp.classes.linkAction.RedirectRequest,
$.pkp.classes.linkAction.LinkActionRequest);
//
// Public methods
//
/**
* @inheritDoc
*/
$.pkp.classes.linkAction.RedirectRequest.prototype.activate =
function(element, event) {
var options = this.getOptions();
window.open(options.url, options.name,
/** @type {{specs: string}} */ (options).specs);
return /** @type {boolean} */ (this.parent('activate', element, event));
};
}(jQuery));