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 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 | 20x 20x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 24x 48x 24x 84x 48x 48x 48x 48x 48x 574x 574x 574x 1396x 1396x 686x 686x 686x 289x 225x 64x 64x 574x 574x 64x 686x 133x 24x | 'use strict'; /** * Extension to display full screen item picker to choose elements from a grid * * @author Pierre Allard <pierre.allard@akeneo.com> * @copyright 2017 Akeneo SAS (http://www.akeneo.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) */ define( [ 'jquery', 'underscore', 'oro/translator', 'backbone', 'routing', 'pim/form', 'pim/template/common/item-picker', 'pim/template/common/item-picker-basket', 'oro/datagrid-builder', 'oro/mediator', 'pim/fetcher-registry', 'pim/user-context', 'oro/datafilter/product_category-filter', 'require-context', 'pim/menu/resizable' ], function ( $, _, __, Backbone, Routing, BaseForm, template, basketTemplate, datagridBuilder, mediator, FetcherRegistry, UserContext, CategoryFilter, requireContext, Resizable ) { return BaseForm.extend({ template: _.template(template), basketTemplate: _.template(basketTemplate), events: { 'click .remove-item': 'removeItemFromBasket' }, imagePathMethod: () => { throw new Error('You have to define "imagePathMethod" method using "setImagePathMethod" method.') }, labelMethod: () => { throw new Error('You have to define "labelMethod" method using "setLabelMethod" method.') }, title: '', /** * {@inheritdoc} */ initialize: function (config) { this.datagridModel = null; this.config = config.config; this.title = __(this.config.title); Iif (undefined === this.config.datagridName) { throw new Error('You have to add parameter "datagridName" to the configuration of this module.'); } Iif (undefined === this.config.categoryTreeRoute) { throw new Error( 'You have to add parameter "categoryTreeRoute" to the configuration of this module.' ); } BaseForm.prototype.initialize.apply(this, arguments); }, /** * {@inheritdoc} */ configure: function () { this.datagrid = { name: this.config.datagridName, paramName: 'itemCodes' }; mediator.on('datagrid:selectModel:' + this.datagrid.name, this.selectModel.bind(this)); mediator.on('datagrid:unselectModel:' + this.datagrid.name, this.unselectModel.bind(this)); mediator.on('datagrid_collection_set_after', this.updateChecked.bind(this)); mediator.on('datagrid_collection_set_after', this.setDatagrid.bind(this)); mediator.on('grid_load:complete', this.updateChecked.bind(this)); mediator.once('column_form_listener:initialized', function onColumnListenerReady(gridName) { Iif (!this.configured) { mediator.trigger( 'column_form_listener:set_selectors:' + gridName, { included: '#item-picker-append-field' } ); } }.bind(this)); return BaseForm.prototype.configure.apply(this, arguments); }, /** * {@inheritdoc} */ render: function () { Iif (!this.configured) { return this; } this.$el.html(this.template({ locale: this.getLocale(), datagridIdentifier: this.datagrid.name })); this.renderGrid(this.datagrid); this.setupResizableColumn(); return this.renderExtensions(); }, /** * Make the categories tree resizable. Because of flexbox we get the * rendered width of the column and use that as the minimum. */ setupResizableColumn() { const resizableColumn = this.$('.ui-resizable-container--column'); const originalColumnWidth = resizableColumn.outerWidth(); Resizable.set({ minWidth: originalColumnWidth, maxWidth: 500, container: this.$('.ui-resizable-container--column-child'), storageKey: 'item-picker' }); }, /** * {@inheritdoc} */ shutdown() { Resizable.destroy(); return BaseForm.prototype.shutdown.apply(this, arguments); }, /** * Render the item grid */ renderGrid: function () { const urlParams = { alias: this.datagrid.name, params: { dataLocale: this.getLocale(), _filter: { category: { value: { categoryId: -2 }}, // -2 = all categories scope: { value: this.getScope() } } } }; /* jshint nonew: false */ new CategoryFilter( urlParams, this.config.datagridName, this.config.categoryTreeRoute, '#item-picker-tree' ); $.get(Routing.generate('pim_datagrid_load', urlParams)).done(function (response) { this.$('#grid-' + this.datagrid.name).data( { 'metadata': response.metadata, 'data': JSON.parse(response.data) } ); let resolvedModules = []; response.metadata.requireJSModules.concat(['oro/datagrid/pagination-input']) .forEach(function(module) { resolvedModules.push(requireContext(module)) }); datagridBuilder(resolvedModules); }.bind(this)); }, /** * Triggered by the event 'datagrid_collection_set_after' to keep a locale reference to * the grid model #gridCrap * * @param {Object} datagridModel */ setDatagrid: function (datagridModel) { this.datagridModel = datagridModel; }, /** * Triggered by the datagrid:selectModel:gridName event * * @param {Object} model */ selectModel: function (model) { this.addItem(model.get(this.config.columnName)); }, /** * Triggered by the datagrid:unselectModel:gridName event * * @param {Object} model */ unselectModel: function (model) { this.removeItem(model.get(this.config.columnName)); }, /** * Add an item to the basket * * @param {string} code * * @return this */ addItem: function (code) { let items = this.getItems(); items.push(code); items = _.uniq(items); this.setItems(items); return this; }, /** * Remove an item from the collection * * @param {string} code * * @return this */ removeItem: function (code) { let items = _.without(this.getItems(), code); this.setItems(items); return this; }, /** * Get all items in the collection * * @return {Array} */ getItems: function () { const items = $('#item-picker-append-field').val(); return (!_.isUndefined(items) && '' !== items) ? items.split(',') : []; }, /** * Set items * * @param {Array} itemCodes * * @return this */ setItems: function (itemCodes) { $('#item-picker-append-field').val(itemCodes.join(',')); this.updateBasket(itemCodes); return this; }, /** * Update the checked rows in the grid according to the current model * * @param {Object} datagrid */ updateChecked: function (datagrid) { if (datagrid.inputName !== this.datagrid.name) { return; } const items = this.getItems(); datagrid.models.forEach((row) => { Iif (items.includes(row.get(this.config.columnName))) { row.set('is_checked', true); } else { row.set('is_checked', null); } }); this.setItems(items); }, /** * Remove an item from the basket (triggered by 'click .remove-item') * * @param {Event} event */ removeItemFromBasket: function (event) { this.removeItem(event.currentTarget.dataset.itemcode); if (this.datagridModel) { this.updateChecked(this.datagridModel); } }, /** * Fetches the new items and render the basket. * * In the case where asset codes are integers, even if their order is correctly managed by the backend, the * fetcher will reorganize them, sorting them by code ascending. As "itemCodes" contains the codes in the * correct order, we reorder the assets according to this list of code. */ updateBasket: function (itemCodes) { FetcherRegistry.getFetcher(this.config.fetcher).fetchByIdentifiers(this.getItems()).then(items => { let orderedItems = []; itemCodes.forEach(itemCode => { orderedItems = orderedItems.concat(items.filter(item => item.code === itemCode)); }); this.renderBasket(orderedItems); this.delegateEvents(); }); }, /** * Renders the basket to update its content * @param items */ renderBasket: function (items) { this.$('.basket').html(this.basketTemplate({ items: items, title: __('pim_enrich.entity.product.module.basket.title'), emptyLabel: __('pim_enrich.entity.product.module.basket.empty_basket'), imagePathMethod: this.imagePathMethod.bind(this), columnName: this.config.columnName, identifierName: this.config.columnName, labelMethod: this.labelMethod.bind(this), itemCodeMethod: this.itemCodeMethod.bind(this) })); }, /** * Updates the function generating the path of the basket images * * @param {Function} f */ setImagePathMethod: function (f) { this.imagePathMethod = f; }, /** * Updates the function generating the label of the basket images * * @param {Function} f */ setLabelMethod: function (f) { this.labelMethod = f; }, /** * Allows overriding of the default title * * @param {String} title */ setCustomTitle: function (title) { this.title = title; }, /** * Returns the method to display unique codes for basket deletion * * @param {Object} item * @returns {string} */ itemCodeMethod: function (item) { return item[this.config.columnName]; }, /** * Get the current locale * * @return {string} */ getLocale: function () { return UserContext.get('catalogLocale'); }, /** * Get the current scope * * @return {string} */ getScope: function () { return UserContext.get('catalogScope'); } }); } ); |