Skip to content

Commit

Permalink
pkp#988 JS linting
Browse files Browse the repository at this point in the history
  • Loading branch information
asmecher committed Feb 22, 2016
1 parent 84a8c6c commit 76ec4b5
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 29 deletions.
23 changes: 13 additions & 10 deletions js/controllers/UploaderHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
uploaderOptions.resize = options.resize;
}
uploaderOptions = $.extend(
{},
this.self('DEFAULT_PROPERTIES_'),
uploaderOptions
);
{},
this.self('DEFAULT_PROPERTIES_'),
uploaderOptions
);

// Create the uploader with the puploader plug-in.
// Setup the upload widget.
Expand Down Expand Up @@ -108,6 +108,7 @@
pluploader.start();
};


/**
* Update the progress indicator for a file
* @param {Object} caller The original context in which the callback was called.
Expand All @@ -122,23 +123,23 @@
this.$progressBar.css('width', file.percent + '%');
};


/**
* Indicate the file upload has completed
* @param {Object} caller The original context in which the callback was called.
* @param {Object} pluploader The pluploader object.
* @param {Object} file The data of the uploaded file.
*
* @param {{response: string}} response
*/
$.pkp.controllers.UploaderHandler.prototype.
uploadComplete = function(caller, pluploader, file, response) {
var jsonData = $.parseJSON(response.response);
var jsonData = $.parseJSON(response.response), filename = file.name;

if (!jsonData.status) {
this.showError(jsonData.content);
return;
}

var filename = file.name;
if (typeof jsonData.uploadedFile !== 'undefined') {
filename = jsonData.uploadedFile.name || jsonData.uploadedFile.fileLabel;

Expand All @@ -154,22 +155,24 @@

this.$fileName.html(filename);
this.updateStatus('complete');
this.$progress.html(0);
this.$progress.html('0');
this.$progressBar.css('width', 0);
};


/**
* Handle error revents from plupload
* @param {Object} caller The original context in which the callback was called.
* @param {Object} pluploader The pluploader object.
* @param {Object} file The data of the uploaded file.
* @param {{message: string}} err An object describing an error condition
*
*/
$.pkp.controllers.UploaderHandler.prototype.
handleError = function(caller, pluploader, err) {
this.showError(err.message);
};


/**
* Display an error if encountered during upload
* @param {string} msg The error message
Expand All @@ -178,7 +181,7 @@
$.pkp.controllers.UploaderHandler.prototype.
showError = function(msg) {

this.$progress.html(0);
this.$progress.html('0');
this.$progressBar.css('width', 0);
this.updateStatus('error');
this.getHtmlElement().find('.pkpUploaderError').html(msg);
Expand Down
9 changes: 3 additions & 6 deletions js/controllers/wizard/WizardHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -556,8 +556,9 @@

if (options.continueButtonText) {
// Add continue/finish button.
$continueButton = $('<button id="continueButton" class="pkp_button"></button>')
.text(options.continueButtonText);
$continueButton = $(
'<button id="continueButton" class="pkp_button"></button>')
.text(options.continueButtonText);
$wizardButtons.append($continueButton);

$progressIndicator = $(
Expand Down Expand Up @@ -587,8 +588,6 @@

/**
* Disable the continue button
*
* @private
*/
$.pkp.controllers.wizard.WizardHandler.prototype.disableContinueButton =
function() {
Expand All @@ -598,8 +597,6 @@

/**
* Enable the continue button
*
* @private
*/
$.pkp.controllers.wizard.WizardHandler.prototype.enableContinueButton =
function() {
Expand Down
11 changes: 7 additions & 4 deletions js/controllers/wizard/fileUpload/FileUploadWizardHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@
* original event is triggered by plupload and passed via
* FileUploadFormHandler.
*
* See the @TODO note under FileUPloadFormHandler::handleFilesRemoved
* See the TODO note under FileUPloadFormHandler::handleFilesRemoved
*
* @param {$.pkp.controllers.form.AjaxFormHandler} callingForm The form
* that triggered the event.
Expand All @@ -306,16 +306,19 @@
* @param {array} file Array of files removed
*/
$.pkp.controllers.wizard.fileUpload.FileUploadWizardHandler.
prototype.handleRemovedFiles = function(callingForm, event, pluploader, file) {
prototype.handleRemovedFiles =
function(callingForm, event, pluploader, file) {

var i;

if (typeof file === 'undefined' || !file.length) {
return;
}

// There's no error handling done for the response because we don't
// really have an elegant way to handle or display a failed deletion
for (var i in file) {
if (typeof file[i].storedData === 'undefined' ) {
for (i in file) {
if (typeof file[i].storedData === 'undefined') {
return;
}
$.post(this.deleteUrl_, file[i].storedData);
Expand Down
24 changes: 15 additions & 9 deletions js/controllers/wizard/fileUpload/form/FileUploadFormHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
this.uploaderSetup(options.$uploader);

// Enable/disable the uploader and genre selection based on selection
this.$revisedFileSelector = $form.find('#revisedFileId')
this.$revisedFileSelector_ = $form.find('#revisedFileId')
.change(this.callbackWrapper(this.revisedFileChange));
if (this.hasGenreSelector_) {
this.$genreSelector = $form.find('#genreId')
Expand All @@ -76,13 +76,14 @@
$.pkp.controllers.wizard.fileUpload.form.FileUploadFormHandler
.hasFileSelector_ = false;


/**
* The file upload form's file selector if available.
* @private
* @type {boolean}
*/
$.pkp.controllers.wizard.fileUpload.form.FileUploadFormHandler
.$revisedFileSelector = null;
.$revisedFileSelector_ = null;


/**
Expand All @@ -93,6 +94,7 @@
$.pkp.controllers.wizard.fileUpload.form.FileUploadFormHandler
.hasGenreSelector_ = false;


/**
* The file upload form's genre selector if available.
* @private
Expand Down Expand Up @@ -126,7 +128,7 @@
* @type {Object}
*/
$.pkp.controllers.wizard.fileUpload.form.FileUploadFormHandler
.$uploader = null;
.$uploader_ = null;


//
Expand Down Expand Up @@ -169,8 +171,8 @@

// Add the revised file to the upload message.
if (this.hasFileSelector_) {
this.$revisedFileSelector.attr('disabled', 'disabled');
multipartParams.revisedFileId = this.$revisedFileSelector.val();
this.$revisedFileSelector_.attr('disabled', 'disabled');
multipartParams.revisedFileId = this.$revisedFileSelector_.val();
} else {
if (this.presetRevisedFileId_ !== null) {
multipartParams.revisedFileId = this.presetRevisedFileId_;
Expand Down Expand Up @@ -227,7 +229,7 @@
* Pass the `FilesRemoved` event from plupload on to FileUploadWizardHandler
* so it can delete the file.
*
* @TODO this is necessary because only the FileUploadWizardHandler knows
* TODO this is necessary because only the FileUploadWizardHandler knows
* the delete URL. But other file upload utilities could benefit from this
* feature, so it would be best to internalize this functionality in the
* UploadHandler by passing in a deleteURL option. This is a task that
Expand Down Expand Up @@ -269,10 +271,10 @@
revisedFileChange = function(revisedFileElement, event) {

// Enable/disable the genre field when a revision is selected
if (!this.$revisedFileSelector.val()) {
if (!this.$revisedFileSelector_.val()) {
this.$genreSelector.removeAttr('disabled');
} else {
this.$genreSelector.val(this.fileGenres_[this.$revisedFileSelector.val()]);
this.$genreSelector.val(this.fileGenres_[this.$revisedFileSelector_.val()]);
this.$genreSelector.attr('disabled', 'disabled');
}

Expand Down Expand Up @@ -315,11 +317,13 @@
/**
* Adjust the display of the plupload component depending on required
* settings
* @private
*/
$.pkp.controllers.wizard.fileUpload.form.FileUploadFormHandler.prototype.
setUploaderVisibility_ = function() {

if ( (this.hasGenreSelector_ && this.$genreSelector.val()) || this.$revisedFileSelector.val()) {
if ((this.hasGenreSelector_ && this.$genreSelector.val())
|| this.$revisedFileSelector_.val()) {
this.showUploader_();
} else {
this.hideUploader_();
Expand All @@ -329,6 +333,7 @@

/**
* Hide the plupload component
* @private
*/
$.pkp.controllers.wizard.fileUpload.form.FileUploadFormHandler.prototype.
hideUploader_ = function() {
Expand All @@ -338,6 +343,7 @@

/**
* Show the the plupload component
* @private
*/
$.pkp.controllers.wizard.fileUpload.form.FileUploadFormHandler.prototype.
showUploader_ = function() {
Expand Down
17 changes: 17 additions & 0 deletions tools/closure-externs.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,30 @@ tinyMCEObject.prototype.onSetContent.remove = function(param1) {};
var tinyMCE;

var plupload = {};
plupload.Uploader.prototype.init = function() {};

/**
* @param {Object} options
* @constructor
*/
plupload.Uploader = function (options) {};

/**
* @param {string|number} p
*/
plupload.Uploader.prototype.percent = function(p) {};

/**
* @param {string} f
*/
plupload.Uploader.prototype.removeFile = function(f) {};

/**
* @param {!string} eventName
* @param {Function} f
*/
plupload.Uploader.prototype.bind = function(eventName, f) {};


$.pkp.locale = {
search_noKeywordError: '',
Expand Down

0 comments on commit 76ec4b5

Please sign in to comment.