From 30a57dbbdcd8b1ebd1bf285d650a375c983f0c8a Mon Sep 17 00:00:00 2001 From: Alexandr Parkhomenko Date: Tue, 3 Jan 2017 21:16:39 +0200 Subject: [PATCH 01/29] CRM-6658: Widget "Average Lifetime Sales" is not working correctly with empty custom date --- .../Resources/public/js/widget/date-range.js | 74 +++++++++++++------ .../views/Js/default_templates.js.twig | 2 +- 2 files changed, 53 insertions(+), 23 deletions(-) diff --git a/src/Oro/Bundle/DashboardBundle/Resources/public/js/widget/date-range.js b/src/Oro/Bundle/DashboardBundle/Resources/public/js/widget/date-range.js index 09c29e33697..4091ecf4092 100644 --- a/src/Oro/Bundle/DashboardBundle/Resources/public/js/widget/date-range.js +++ b/src/Oro/Bundle/DashboardBundle/Resources/public/js/widget/date-range.js @@ -16,13 +16,21 @@ define(function(require) { value: -5 }, + fieldsDataName: { + datePart: 'date_part', + customPart: 'custom_part' + }, + + domCache: null, + /** * @inheritDoc */ events: { + 'change select': 'skipOnChangeFilterTypeHandler', 'change .date-visual-element': '_onClickUpdateCriteria', 'change select[name=date_part], input[name$="[type]"]': 'onChangeFilterType', - 'change select[name=""]': 'onChangeFilterTypeView' + 'change select[data-name$="_part"]': 'onChangeFilterTypeView' }, /** @@ -35,22 +43,30 @@ define(function(require) { options.$form.on('submit' + this.eventNamespace(), _.bind(this.onSubmit, this)); }, - onSubmit: function(e) { + createDomCache: function() { + this.domCache = { + $datePart: this.$('select[data-name="' + this.fieldsDataName.datePart + '"]'), + $customPart: this.$('select[data-name="' + this.fieldsDataName.customPart + '"]'), + $dateTypeCriteriaValue: this.$(this.criteriaValueSelectors.date_type) + }; + }, + + onSubmit: function() { var value = _.extend({}, this.emptyValue, this.getValue()); if (_.values(this.typeValues).indexOf(parseInt(value.type)) !== -1 && !value.value.start && !value.value.end ) { - this.$('select[name=""]').eq(0).val(this.typeDefinedValues.all_time).change(); - this.applyValue(); + var defaultTypeValue = this.getDefaultTypeValue(); + this.domCache.$datePart.val(defaultTypeValue).change(); } }, onChangeFilterTypeView: function(e) { var val = parseInt($(e.target).val()); if (val === this.customChoice.value) { - val = this.$('select[name=""]').eq(1).val(); + val = this.domCache.$customPart.val(); } - this.$(this.criteriaValueSelectors.date_type).val(val).change(); + this.domCache.$dateTypeCriteriaValue.val(val).change(); this.applyValue(); }, @@ -71,6 +87,7 @@ define(function(require) { return; } + this.domCache = null; this.options.$form.off(this.eventNamespace()); WidgetConfigDateRangeFilter.__super__.dispose.apply(this, arguments); }, @@ -80,31 +97,32 @@ define(function(require) { var type = parseInt(value, 10); if (!isNaN(type)) { - var $select = this.$('.selector:has(select[name=""]):eq(1), select[name=""]:eq(1)').eq(0); - if (_.values(this.typeDefinedValues).indexOf(type) > -1) { - $select.hide(); + if (_.values(this.typeDefinedValues).indexOf(type) === -1) { + this.domCache.$customPart.show(); } else { - // set correct width of uniform widget in case