Press n or j to go to the next uncovered block, b, p or k for the previous block.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 | 302x 302x 383x 383x 383x 383x 383x 383x 383x 34x 383x 383x 25x 3x 383x 383x 383x 383x 36x 743x 743x 743x 18x 743x 743x 5652x 5652x 146x 154x 154x 35x 35x 35x 35x 35x 35x 154x 342x 3x 14x 9x 9x 9x 9x 9x 9x 9x 9x 3x 4x 4x 470x 43x 43x 3x 3x 97x 479x 40x 40x 80x 7x 7x 1x 1x 22x 1x 1x 1x 2x 8x 2x 2x 25x 8x 2x 766x 766x 766x | 'use strict'; /** * Copy extension * * @author Julien Sanchez <julien@akeneo.com> * @author Filips Alpe <filips@akeneo.com> * @author Yohan Blain <yohan.blain@akeneo.com> * @copyright 2015 Akeneo SAS (http://www.akeneo.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ define( [ 'jquery', 'underscore', 'pim/form', 'oro/mediator', 'pim/template/form/tab/attribute/copy', 'pim/form/common/attributes/copy-field', 'pim/field-manager', 'pim/attribute-manager', 'pim/user-context', 'pim/fetcher-registry', 'pim/i18n' ], function ( $, _, BaseForm, mediator, template, CopyField, FieldManager, AttributeManager, UserContext, FetcherRegistry, i18n ) { return BaseForm.extend({ template: _.template(template), className: 'AknAttributeActions-copyActions attribute-copy-actions', copyFields: {}, copying: false, locale: null, scope: null, scopeLabel: null, events: { 'click .stop-copying': 'stopCopying', 'click .select-all': 'selectAll', 'click .select-all-visible': 'selectAllVisible', 'click .select-none': 'selectNone', 'click .copy': 'copy' }, /** * Configure this extension * * @returns {Promise} */ configure: function () { this.locale = UserContext.get('catalogLocale'); this.scope = UserContext.get('catalogScope'); this.getScopeLabel(this.scope).then(function (scopeLabel) { this.scopeLabel = scopeLabel; }.bind(this)); this.listenTo(this.getRoot(), 'pim_enrich:form:field:extension:add', this.addFieldExtension); this.listenTo(this.getRoot(), 'pim_enrich:form:scope_switcher:pre_render', this.initScope.bind(this)); this.listenTo(this.getRoot(), 'pim_enrich:form:scope_switcher:change', function (eventScope) { Iif ('copy_product' === eventScope.context) { this.setScope(eventScope.scopeCode); } }.bind(this)); this.listenTo(this.getRoot(), 'pim_enrich:form:locale_switcher:pre_render', this.initLocale.bind(this)); this.listenTo(this.getRoot(), 'pim_enrich:form:locale_switcher:change', function (eventLocale) { if ('copy_product' === eventLocale.context) { this.setLocale(eventLocale.localeCode); } }.bind(this)); this.listenTo(this.getRoot(), 'pim_enrich:form:start_copy', this.startCopying.bind(this)); return this.getScopeLabel(this.scope).then(function (scopeLabel) { this.scopeLabel = scopeLabel; }.bind(this)).then(function () { return BaseForm.prototype.configure.apply(this, arguments) }.bind(this)); }, /** * Return the values object from which data must be copied * * @returns {Object} */ getSourceData: function () { return this.getFormData().values; }, /** * Render the copy panel * * @returns {Object} */ render: function () { this.trigger('comparison:change', this.copying); this.$el.html(this.template({'copying': this.copying})); if (this.copying) { this.renderExtensions(); } this.delegateEvents(); return this; }, /** * Render the copy element inside each field that can be copied * * @param {Object} event */ addFieldExtension: function (event) { var field = event.field; if (this.copying && this.canBeCopied(field)) { field.addElement('comparison', this.code, this.getCopyField(field)); } }, /** * Get or create a copy field object corresponding to the specified field * * @param {Field} field * * @returns {CopyField} */ getCopyField: function (field) { var code = field.attribute.code; if (!_.has(this.copyFields, code)) { var sourceData = this.getSourceData(); var copyField = new CopyField(field.attribute); copyField.setContext({ locale: this.locale, scope: this.scope, scopeLabel: i18n.getLabel(this.scopeLabel, this.locale, this.scope) }); copyField.setValues(sourceData[code]); copyField.setField(field); this.copyFields[code] = copyField; } return this.copyFields[code]; }, /** * Indicate if the specified field can be copied * * @param {Field} field * @returns {boolean} */ canBeCopied: function (field) { return (field.attribute.localizable || field.attribute.scopable) && ( !field.attribute.is_locale_specific || _.contains(field.attribute.available_locales, this.getLocale()) ); }, /** * Launch the copy process for selected fields */ copy: function () { _.each(this.copyFields, function (copyField) { if (copyField.selected && copyField.field && copyField.field.isEditable()) { var formValues = this.getFormModel().get('values'); var oldValue = AttributeManager.getValue( formValues[copyField.field.attribute.code], copyField.field.attribute, UserContext.get('catalogLocale'), UserContext.get('catalogScope') ); Iif (undefined === oldValue) { return; } var currentValue = copyField.getCurrentValue(); Iif (undefined === currentValue) { return; } oldValue.data = currentValue.data; this.getRoot().trigger('pim_enrich:form:entity:update_state'); copyField.setSelected(false); } }.bind(this)); this.trigger('copy:copy-fields:after'); }, /** * Enter in copy mode */ startCopying: function () { this.copying = true; this.triggerContextChange(); }, /** * Close copy mode */ stopCopying: function () { this.getRoot().trigger('pim_enrich:form:stop_copy'); this.copying = false; this.triggerContextChange(); }, /** * Initialize the locale if there is none, or modify it by reference if there is already one * * @param {Object} eventLocale * @param {String} eventLocale.context * @param {String} eventLocale.localeCode */ initLocale: function (eventLocale) { if ('copy_product' === eventLocale.context) { Iif (undefined === this.getLocale()) { this.setLocale(eventLocale.localeCode); } else { eventLocale.localeCode = this.getLocale(); } } }, /** * Change the locale for copy context * * @param {string} locale */ setLocale: function (locale) { this.locale = locale; this.triggerContextChange(); }, /** * Get the current locale for copy * * @returns {string} */ getLocale: function () { return this.locale; }, /** * Initialize the scope if there is none, or modify it by reference if there is already one * * @param {Object} scopeEvent * @param {string} scopeEvent.context * @param {string} scopeEvent.scopeCode */ initScope: function (scopeEvent) { if ('copy_product' === scopeEvent.context) { Iif (undefined === this.getScope()) { this.setScope(scopeEvent.scopeCode); } else { scopeEvent.scopeCode = this.getScope(); } } }, /** * Change the scope for copy context * * @param {string} scopeCode */ setScope: function (scopeCode) { this.getScopeLabel(scopeCode).then(function (scopeLabel) { this.scopeLabel = scopeLabel; this.scope = scopeCode; this.triggerContextChange(); }.bind(this)); }, /** * Get the current scope for copy * * @returns {string} */ getScope: function () { return this.scope; }, /** * Reset copy fields cache then trigger the context change event */ triggerContextChange: function () { this.copyFields = {}; this.trigger('copy:context:change'); }, /** * Mark all fields (from all attribute groups) as selected */ selectAll: function () { var fieldPromises = []; _.each(this.getSourceData(), function (value, attributeCode) { fieldPromises.push(FieldManager.getField(attributeCode)); }.bind(this)); $.when.apply(this, fieldPromises) .then(function () { this.selectFields(arguments); }.bind(this)); }, /** * Mark all visible fields (from active attribute group) as selected */ selectAllVisible: function () { this.selectFields(FieldManager.getVisibleFields()); }, /** * Mark all fields as unselected */ selectNone: function () { this.selectFields([]); }, /** * Unselect all field */ unselectAll: function () { _.each(this.copyFields, function (field) { field.setSelected(false); }); }, /** * Mark specified fields as selected and trigger the select event * * @param {Field[]} fields */ selectFields: function (fields) { this.unselectAll(); _.each(fields, function (field) { if (this.canBeCopied(field)) { this.getCopyField(field).setSelected(true); } }.bind(this)); this.trigger('copy:select:after'); }, /** * Get the scope label with the given scope code * * @param {string} scopeCode * * @returns {Promise} */ getScopeLabel: function (scopeCode) { return FetcherRegistry.getFetcher('channel').fetchAll().then(function (channels) { var scope = _.findWhere(channels, { code: scopeCode }); return scope.labels; }); } }); } ); |