Skip to content

Commit

Permalink
Merge pull request #423 from magento-vanilla/PR2-bugs
Browse files Browse the repository at this point in the history
[Vanilla] Tasks + bug fixes
  • Loading branch information
guz-anton committed Mar 16, 2016
2 parents 357713e + d9d1b54 commit f227f6a
Show file tree
Hide file tree
Showing 23 changed files with 517 additions and 155 deletions.
2 changes: 2 additions & 0 deletions app/code/Magento/Catalog/Model/Category/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,11 @@ public function getDefaultMetaData($result)
$result['use_config.default_sort_by']['default'] = true;
$result['use_config.filter_price_range']['default'] = true;
if ($this->request->getParam('store') && $this->request->getParam('id')) {
$result['use_default.url_key']['checked'] = true;
$result['use_default.url_key']['default'] = true;
$result['use_default.url_key']['visible'] = true;
} else {
$result['use_default.url_key']['checked'] = false;
$result['use_default.url_key']['default'] = false;
$result['use_default.url_key']['visible'] = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,36 @@
*/

define([
'Magento_Ui/js/form/element/abstract'
], function (Abstract) {
'Magento_Ui/js/form/element/single-checkbox'
], function (Checkbox) {
'use strict';

return Abstract.extend({
return Checkbox.extend({
defaults: {
imports: {
handleUseDefault: '${ $.parentName }.use_default.url_key:checked',
urlKey: '${ $.provider }:data.url_key'
},
listens: {
urlKey: 'handleChanges'
},
modules: {
useDefault: '${ $.parentName }.use_default.url_key'
}
},

/**
* Disable checkbox field, when 'url_key' field without changes
* Disable checkbox field, when 'url_key' field without changes or 'use default' field is checked
*/
handleChanges: function (newValue) {
if (newValue !== this.getInitialValue()) {
this.disabled(false);
} else {
this.disabled(true);
}
this.disabled(newValue === this.valueMap['true'] || this.useDefault.checked);
},

/**
* Set real 'url_key' to 'url_key_create_redirect' when field is checked
* Disable checkbox field, when 'url_key' field without changes or 'use default' field is checked
*/
onUpdate: function () {
this._super();

if (this.value()) {
this.value(this.initialValue);
} else {
this.value(0);
}
this._super();
handleUseDefault: function (checkedUseDefault) {
this.disabled(this.urlKey === this.valueMap['true'] || checkedUseDefault);
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,14 @@ public function afterGetAttributesMeta(
if (isset($result['url_key'])) {
if ($category && $category->getId()) {
if ($category->getLevel() == 1) {
$result['url_key']['arguments']['data']['config']['visible'] = false;
$result['url_key_create_redirect']['arguments']['data']['config']['visible'] = false;
$result['url_key_group']['arguments']['data']['disabled'] = true;
$result['url_key_group']['componentDisabled'] = true;
} else {
$result['url_key_create_redirect']['arguments']['data']['config']['value'] = $category->getUrlKey();
$result['url_key_create_redirect']['arguments']['data']['config']['disabled'] = true;
$result['url_key_create_redirect']['valueMap']['true'] = $category->getUrlKey();
$result['url_key_create_redirect']['value'] = $category->getUrlKey();
$result['url_key_create_redirect']['disabled'] = true;
}
} else {
$result['url_key_create_redirect']['arguments']['data']['config']['visible'] = false;
$result['url_key_create_redirect']['visible'] = false;
}
}
return $result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*/
namespace Magento\CatalogUrlRewrite\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Api\Data\ProductAttributeInterface;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Store\Model\ScopeInterface;
use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Catalog\Api\Data\ProductAttributeInterface as AC;
use Magento\Ui\Component\Form\Element\Checkbox;
use Magento\Ui\Component\Form\Element\DataType\Text;
use Magento\Ui\Component\Form\Field;
Expand Down Expand Up @@ -80,7 +80,7 @@ public function modifyData(array $data)
*/
protected function addUrlRewriteCheckbox(array $meta)
{
$urlPath = $this->getElementArrayPath($meta, ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY);
$urlPath = $this->getElementArrayPath($meta, AC::CODE_SEO_FIELD_URL_KEY);

if ($urlPath) {
$containerPath = $this->arrayManager->slicePath($urlPath, 0, -2);
Expand All @@ -105,14 +105,16 @@ protected function addUrlRewriteCheckbox(array $meta)
'componentType' => Field::NAME,
'formElement' => Checkbox::NAME,
'dataType' => Text::NAME,
'component' => 'Magento_CatalogUrlRewrite/js/components/url-key-handle-changes',
'component' => 'Magento_Catalog/js/components/url-key-handle-changes',
'valueMap' => [
'false' => '',
'true' => $urlKey
],
'imports' => [
'urlKey' => '${ $.provider }:data.product.' . AC::CODE_SEO_FIELD_URL_KEY,
'handleUseDefault' => '${ $.parentName }.url_key:isUseDefault',
'handleChanges' => '${ $.provider }:data.product.'
. ProductAttributeInterface::CODE_SEO_FIELD_URL_KEY,
. AC::CODE_SEO_FIELD_URL_KEY,
],
'description' => __('Create Permanent Redirect for old URL'),
'dataScope' => 'url_key_create_redirect',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
<item name="description" xsi:type="string" translate="true">Create Permanent Redirect for old URL</item>
<item name="dataType" xsi:type="string">boolean</item>
<item name="formElement" xsi:type="string">checkbox</item>
<item name="disabled" xsi:type="boolean">true</item>
<item name="sortOrder" xsi:type="number">15</item>
<item name="component" xsi:type="string">Magento_Catalog/js/components/url-key-handle-changes</item>
<item name="valueMap" xsi:type="array">
<item name="false" xsi:type="number">0</item>
</item>
</item>
</argument>
</field>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ define([
*/
applyAction: function (action) {
var targetName = action.targetName,
params = action.params,
params = action.params || [],
actionName = action.actionName,
target;

Expand All @@ -66,7 +66,8 @@ define([
target = registry.async(targetName);

if (target && typeof target === 'function' && actionName) {
target(actionName, params);
params.unshift(actionName);
target.apply(target, params);
}
},

Expand Down
30 changes: 17 additions & 13 deletions app/code/Magento/Ui/view/base/web/js/form/components/insert-form.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,35 +14,39 @@ define([
* Get page actions element.
*
* @param {String} elem
* @param {String} actionsSelector
* @param {String} actionsClass
* @returns {String}
*/
function getPageActions(elem, actionsSelector) {
var $el = $('<div/>').html(elem),
$wrapper = $('<div/>').addClass('page-main-actions');
function getPageActions(elem, actionsClass) {
var el = document.createElement('div');

return $wrapper.html($el.find(actionsSelector)).get(0).outerHTML;
el.innerHTML = elem;

return el.getElementsByClassName(actionsClass)[0];
}

/**
* Return element without page actions toolbar
*
* @param {String} elem
* @param {String} actionsSelector
* @param {String} actionsClass
* @returns {String}
*/
function removePageActions(elem, actionsSelector) {
var $el = $('<div/>').html(elem);
function removePageActions(elem, actionsClass) {
var el = document.createElement('div'),
actions;

$el.find(actionsSelector).remove();
el.innerHTML = elem;
actions = el.getElementsByClassName(actionsClass)[0];
el.removeChild(actions);

return $el.html();
return el.innerHTML;
}

return Insert.extend({
defaults: {
externalFormName: '${ $.ns }.${ $.ns }',
pageActionsSelector: '.page-actions',
pageActionsClass: 'page-actions',
exports: {
prefix: '${ $.externalFormName }:selectorPrefix'
},
Expand Down Expand Up @@ -96,12 +100,12 @@ define([

/** @inheritdoc */
onRender: function (data) {
var actions = getPageActions(data, this.pageActionsSelector);
var actions = getPageActions(data, this.pageActionsClass);

if (!data.length) {
return this;
}
data = removePageActions(data, this.pageActionsSelector);
data = removePageActions(data, this.pageActionsClass);
this.renderActions(actions);
this._super(data);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ define([
self.previousParams = params || {};

$.async({
component: this.name
component: this.name,
ctx: '.' + this.contentSelector
}, function (el) {
self.contentEl = $(el);
self.startRender = true;
Expand Down Expand Up @@ -235,8 +236,6 @@ define([
onRender: function (data) {
this.loading(false);
this.set('content', data);
this.contentEl.children().applyBindings();
this.contentEl.trigger('contentUpdated');
this.isRendered = true;
this.startRender = false;
},
Expand Down
4 changes: 1 addition & 3 deletions app/code/Magento/Ui/view/base/web/js/form/element/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ define([
*/
initConfig: function () {
this._super();

//this.dateFormat = utils.normalizeDate(this.dateFormat);
this.dateFormat = utils.normalizeDate('MM/dd/YYYY');
this.dateFormat = utils.normalizeDate(this.dateFormat);

return this;
},
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/Ui/view/base/web/js/grid/columns/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ define([
*
* @returns {String} Formatted date.
*/
getLabel: function () {
getLabel: function (value, format) {
var date = moment(this._super());

date = date.isValid() ?
date.format(this.dateFormat) :
date.format(format || this.dateFormat) :
'';

return date;
Expand Down
Loading

0 comments on commit f227f6a

Please sign in to comment.