Skip to content

Commit

Permalink
MAGETWO-56849: Clean Up JS files code styles based on black list
Browse files Browse the repository at this point in the history
  • Loading branch information
omiroshnichenko committed Dec 12, 2016
1 parent bf854c4 commit e3bed3f
Show file tree
Hide file tree
Showing 27 changed files with 780 additions and 512 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/view/adminhtml/requirejs-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* See COPYING.txt for license details.
*/

var config = {
var config = {//eslint-disable-line no-unused-vars
map: {
'*': {
categoryForm: 'Magento_Catalog/catalog/category/form',
Expand All @@ -17,4 +17,4 @@ var config = {
deps: [
'Magento_Catalog/catalog/product'
]
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

/*global alert:true*/
define([
'jquery',
Expand All @@ -20,8 +21,10 @@ define([
* @protected
*/
options: {
maxImageUploadCount : 10
maxImageUploadCount: 10
},

/** @inheritdoc */
_create: function () {
var $container = this.element,
imageTmpl = mageTemplate(this.element.find('[data-template=image]').html()),
Expand All @@ -30,22 +33,25 @@ define([
mainClass = 'base-image',
maximumImageCount = 5,
$fieldCheckBox = $container.closest('[data-attribute-code=image]').find(':checkbox'),
isDefaultChecked = $fieldCheckBox.is(':checked');
isDefaultChecked = $fieldCheckBox.is(':checked'),
findElement, updateVisibility;

if (isDefaultChecked) {
$fieldCheckBox.trigger('click');
}

var findElement = function (data) {
findElement = function (data) {//jscs:ignore jsDoc
return $container.find('.image:not(.image-placeholder)').filter(function () {
if (!$(this).data('image')) {
return false;
}

return $(this).data('image').file === data.file;
}).first();
};
var updateVisibility = function () {
updateVisibility = function () {//jscs:ignore jsDoc
var elementsList = $container.find('.image:not(.removed-item)');

elementsList.each(function (index) {
$(this)[index < maximumImageCount ? 'show' : 'hide']();
});
Expand Down Expand Up @@ -78,12 +84,13 @@ define([
});

$galleryContainer.on('moveElement', function (event, data) {
var $element = findElement(data.imageData);
var $element = findElement(data.imageData),
$after;

if (data.position === 0) {
$container.prepend($element);
} else {
var $after = $container.find('.image').eq(data.position);
$after = $container.find('.image').eq(data.position);

if (!$element.is($after)) {
$element.insertAfter($after);
Expand All @@ -93,8 +100,10 @@ define([
});

$container.on('click', '[data-role=make-base-button]', function (event) {
var data;

event.preventDefault();
var data = $(event.target).closest('.image').data('image');
data = $(event.target).closest('.image').data('image');
$galleryContainer.productGallery('setBase', data);
});

Expand All @@ -108,7 +117,7 @@ define([
items: '.image:not(.image-placeholder)',
distance: 8,
tolerance: 'pointer',
stop: function (event, data) {
stop: function (event, data) {//jscs:ignore jsDoc
$galleryContainer.trigger('setPosition', {
imageData: data.item.data('image'),
position: $container.find('.image').index(data.item)
Expand All @@ -122,7 +131,7 @@ define([
dropZone: $dropPlaceholder.closest('[data-attribute-code]'),
acceptFileTypes: /(\.|\/)(gif|jpe?g|png)$/i,
maxFileSize: this.element.data('maxFileSize'),
done: function (event, data) {
done: function (event, data) {//jscs:ignore jsDoc
$dropPlaceholder.find('.progress-bar').text('').removeClass('in-progress');

if (!data.result) {
Expand All @@ -137,35 +146,36 @@ define([
});
}
},
change: function(e, data) {
change: function (e, data) {
if (data.files.length > this.options.maxImageUploadCount) {
$('body').notification('clear').notification('add', {
error: true,
message: $.mage.__('You can\'t upload more than ' + this.options.maxImageUploadCount
+ ' images in one time'),
insertMethod: function(message) {
message: $.mage.__('You can\'t upload more than ' + this.options.maxImageUploadCount +
' images in one time'),
insertMethod: function (message) {//jscs:ignore jsDoc
$('.page-main-actions').after(message);
}
});

return false;
}
}.bind(this),
add: function (event, data) {
add: function (event, data) {//jscs:ignore jsDoc
$(this).fileupload('process', data).done(function () {
data.submit();
});
},
progress: function (e, data) {
progress: function (e, data) {//jscs:ignore jsDoc
var progress = parseInt(data.loaded / data.total * 100, 10);

$dropPlaceholder.find('.progress-bar').addClass('in-progress').text(progress + '%');
},
start: function (event) {
start: function (event) {//jscs:ignore jsDoc
var uploaderContainer = $(event.target).closest('.image-placeholder');

uploaderContainer.addClass('loading');
},
stop: function (event) {
stop: function (event) {//jscs:ignore jsDoc
var uploaderContainer = $(event.target).closest('.image-placeholder');

uploaderContainer.removeClass('loading');
Expand Down
103 changes: 55 additions & 48 deletions app/code/Magento/Catalog/view/adminhtml/web/catalog/category/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,74 +5,81 @@
/**
* Create/edit some category
*/

/* global tree */
define([
'jquery',
'prototype'
], function (jQuery) {
'use strict';

var categorySubmit = function () {//jscs:ignore jsDoc
var activeTab = $('active_tab_id'),
params = {},
fields, i,categoryId, isCreating, path, parentId, currentNode, oldClass, newClass;

var categorySubmit = function (url, useAjax) {
var activeTab = $('active_tab_id');
if (activeTab) {
if (activeTab.tabsJsObject && activeTab.tabsJsObject.tabs('activeAnchor')) {
activeTab.value = activeTab.tabsJsObject.tabs('activeAnchor').prop('id');
if (activeTab) {
if (activeTab.tabsJsObject && activeTab.tabsJsObject.tabs('activeAnchor')) {
activeTab.value = activeTab.tabsJsObject.tabs('activeAnchor').prop('id');
}
}
}

var params = {};
var fields = $('category_edit_form').getElementsBySelector('input', 'select');
for (var i=0; i<fields.length; i++) {
if (!fields[i].name) {
continue;
fields = $('category_edit_form').getElementsBySelector('input', 'select');

for (i = 0; i < fields.length; i++) {
if (!fields[i].name) {
continue;//jscs:ignore
}
params[fields[i].name] = fields[i].getValue();
}
params[fields[i].name] = fields[i].getValue();
}

// Get info about what we're submitting - to properly update tree nodes
var categoryId = params['general[id]'] ? params['general[id]'] : 0;
var isCreating = categoryId == 0; // Separate variable is needed because '0' in javascript converts to TRUE
var path = params['general[path]'].split('/');
var parentId = path.pop();
if (parentId == categoryId) { // Maybe path includes category id itself
// Get info about what we're submitting - to properly update tree nodes
categoryId = params['general[id]'] ? params['general[id]'] : 0;
isCreating = categoryId == 0; // eslint-disable-line eqeqeq
path = params['general[path]'].split('/');
parentId = path.pop();
}

// Make operations with category tree
if (isCreating) {
/* Some specific tasks for creating category */
if (!tree.currentNodeId) {
// First submit of form - select some node to be current
tree.currentNodeId = parentId;
if (parentId == categoryId) { // eslint-disable-line eqeqeq
parentId = path.pop();
}
tree.addNodeTo = parentId;
} else {
/* Some specific tasks for editing category */
// Maybe change category enabled/disabled style
if (tree && tree.storeId==0) {
var currentNode = tree.getNodeById(categoryId);

if (currentNode) {
if (parseInt(params['general[is_active]'])) {
var oldClass = 'no-active-category';
var newClass = 'active-category';
} else {
var oldClass = 'active-category';
var newClass = 'no-active-category';
}
// Make operations with category tree
if (isCreating) {
/* Some specific tasks for creating category */
if (!tree.currentNodeId) {
// First submit of form - select some node to be current
tree.currentNodeId = parentId;
}
tree.addNodeTo = parentId;
} else {
/* Some specific tasks for editing category */
// Maybe change category enabled/disabled style
if (tree && tree.storeId == 0) {// eslint-disable-line eqeqeq, no-lonely-if
currentNode = tree.getNodeById(categoryId);

if (currentNode) {//eslint-disable-line max-depth
if (parseInt(params['general[is_active]'])) {//eslint-disable-line radix, max-depth
oldClass = 'no-active-category';
newClass = 'active-category';
} else {
oldClass = 'active-category';
newClass = 'no-active-category';
}

Element.removeClassName(currentNode.ui.wrap.firstChild, oldClass);
Element.addClassName(currentNode.ui.wrap.firstChild, newClass);
Element.removeClassName(currentNode.ui.wrap.firstChild, oldClass);
Element.addClassName(currentNode.ui.wrap.firstChild, newClass);
}
}
}
}

// Submit form
jQuery('#category_edit_form').trigger('submit');
};
// Submit form
jQuery('#category_edit_form').trigger('submit');
};

return function (config, element) {
config = config || {};
jQuery(element).on('click', function (event) {
jQuery(element).on('click', function () {
categorySubmit(config.url, config.ajax);
});
};
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* See COPYING.txt for license details.
*/

/*global alert:true*/

define([
'jquery',
'Magento_Ui/js/modal/alert'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

define([
'jquery',
'underscore',
Expand All @@ -12,19 +13,25 @@ define([
'use strict';

$.widget('mage.productAttributes', {
/** @inheritdoc */
_create: function () {
this._on({
'click': '_showPopup'
});
},

/**
* @private
*/
_initModal: function () {
var self = this;

this.modal = $('<div id="create_new_attribute"/>').modal({
title: $.mage.__('New Attribute'),
title: $.mage.__('New Attribute'),
type: 'slide',
buttons: [],

/** @inheritdoc */
opened: function () {
$(this).parent().addClass('modal-content-new-attribute');
self.iframe = $('<iframe id="create_new_attribute_container">').attr({
Expand All @@ -35,6 +42,8 @@ define([
self._changeIframeSize();
$(window).off().on('resize.modal', _.debounce(self._changeIframeSize.bind(self), 400));
},

/** @inheritdoc */
closed: function () {
var doc = self.iframe.get(0).document;

Expand All @@ -49,6 +58,10 @@ define([
});
},

/**
* @return {Number}
* @private
*/
_getHeight: function () {
var modal = this.modal.data('modal').modal,
modalHead = modal.find('header'),
Expand All @@ -59,17 +72,28 @@ define([
return modalHeight - modalHeadHeight - modalContentPadding;
},

/**
* @return {Number}
* @private
*/
_getWidth: function () {
return this.modal.width();
},

/**
* @private
*/
_changeIframeSize: function () {
this.modal.parent().outerHeight(this._getHeight());
this.iframe.outerHeight(this._getHeight());
this.iframe.outerWidth(this._getWidth());

},

/**
* @return {String}
* @private
*/
_prepareUrl: function () {
var productSource,
attributeSetId = '';
Expand All @@ -86,6 +110,9 @@ define([
'set=' + attributeSetId;
},

/**
* @private
*/
_showPopup: function () {
this._initModal();
this.modal.modal('openModal');
Expand Down
Loading

0 comments on commit e3bed3f

Please sign in to comment.