handleExport: function() { if (!this.options.exportProcessor) { throw new TypeError('"exportProcessor" is required'); } var exportUrl; if (this.options.isExportPopupRequired) { exportUrl = routing.generate(this.options.exportConfigRoute, $.extend({}, this.routeOptions, { processorAlias: this.options.exportProcessor, filePrefix: this.options.filePrefix })); this._renderDialogWidget({ url: exportUrl, dialogOptions: { title: this.options.exportTitle } }); } else { exportUrl = routing.generate(this.options.exportRoute, $.extend({}, this.routeOptions, { processorAlias: this.options.exportProcessor, filePrefix: this.options.filePrefix })); $.getJSON( exportUrl, function(data) { exportHandler.handleExportResponse(data); } ); } },
'success': _.bind(function() { mediator.execute('hideLoading'); var redirectUrl = ''; var modelName = this.model.get('name'); var saveAndClose = this.workflowManagementView.submitActor && !$(this.workflowManagementView.submitActor).is('[data-action="save_and_stay"]'); if (saveAndClose) { redirectUrl = routing.generate('oro_workflow_definition_view', {name: modelName}); } else { redirectUrl = routing.generate('oro_workflow_definition_update', {name: modelName}); } mediator.once('page:afterChange', function() { messenger.notificationFlashMessage('success', __('Workflow saved.')); messenger.notificationFlashMessage( 'warning', __( 'oro.workflow.translation_rebuild_required', {path: routing.generate('oro_translation_translation_index')} ) ); }); mediator.execute('redirectTo', {url: redirectUrl}, {redirect: true}); }, this),
getTemplateData: function() { var data = ActivityView.__super__.getTemplateData.call(this); data.has_comments = this.options.configuration.has_comments; data.ignoreHead = this.options.ignoreHead; data.collapsed = this.collapsed; data.createdAt = dateTimeFormatter.formatSmartDateTime(data.createdAt); data.updatedAt = dateTimeFormatter.formatSmartDateTime(data.updatedAt); // use special model's method to get activity class name with replaced slashes data.relatedActivityClass = _.escape(this.model.getRelatedActivityClass()); if (data.owner_id) { data.owner_url = routing.generate('oro_user_view', {id: data.owner_id}); } else { data.owner_url = ''; } if (data.editor_id) { data.editor_url = routing.generate('oro_user_view', {id: data.editor_id}); } else { data.editor_url = ''; } data.routing = routing; data.dateFormatter = dateTimeFormatter; data.editable = this.model.get('editable'); data.removable = this.model.get('removable'); return data; },
handleTemplate: function() { if (!this.options.exportTemplateProcessor) { throw new TypeError('"exportTemplateProcessor" is required'); } var exportTemplateUrl; if (this.options.isExportTemplatePopupRequired) { exportTemplateUrl = routing.generate( this.options.exportTemplateConfigRoute, $.extend({}, this.routeOptions, { processorAlias: this.options.exportTemplateProcessor }) ); this._renderDialogWidget({ url: exportTemplateUrl, dialogOptions: { title: this.options.exportTemplateTitle } }); } else { exportTemplateUrl = routing.generate( this.options.exportTemplateRoute, $.extend({}, this.routeOptions, { processorAlias: this.options.exportTemplateProcessor }) ); window.open(exportTemplateUrl); } },
serialize: function() { var data = CommentModel.__super__.serialize.call(this); data.isNew = this.isNew(); data.hasActions = data.removable || data.editable; data.message = this.getMessage(); data.shortMessage = this.getShortMessage(); if (data.owner_id) { data.owner_url = routing.generate('oro_user_view', {id: data.owner_id}); } if (data.editor_id) { data.editor_url = routing.generate('oro_user_view', {id: data.editor_id}); } return data; },
addressUpdateUrl: function() { var address = arguments[0]; return routing.generate( options.addressUpdateRouteName, {'id': address.get('id'), 'entityId': options.entityId} ); }
addToDashboard: function(data) { var wid = 'dashboard-widget-' + data.id; var containerId = 'widget-container-' + wid; var column = data.layout_position[0] ? data.layout_position[0] : 0; $('#dashboard-column-' + column).prepend($('<div id="' + containerId + '"></div>')); var state = { 'id': data.id, 'expanded': data.expanded, 'layoutPosition': data.layout_position }; var widgetParams = { 'widgetType': 'dashboard-item', 'wid': wid, 'url': routing.generate(data.config.route, _.extend(data.config.route_parameters, { '_widgetId': state.id })), 'state': state, 'loadingMaskEnabled': false, 'container': '#' + containerId, 'allowEdit': this.options.allowEdit, 'showConfig': this.options.allowEdit && !_.isEmpty(data.config.configuration), 'widgetName': data.name }; var widget = new DashboardItemWidget(widgetParams); widget.render(); this.add(widget); if (this.options.allowEdit) { $(this.options.columnsSelector).sortable('refresh'); } },
source: function(query, process) { var self = this; if (_.isArray(this.sourceUrl)) { process(this.sourceUrl); this.render(); } else if (!_.isUndefined(this.cache[query])) { process(this.cache[query]); this.render(); } else { var url = routing.generate(this.sourceUrl, {'query': query}); $.get(url, _.bind(function(data) { this.data = data; var result = []; _.each(data, function(item, key) { result.push({ key: key, item: item }); }); this.cache[query] = result; process(result); self.render(); }, this)); } },
onClickReadStatus: function(e) { e.stopPropagation(); var model = this.model; var status = model.get('seen'); var url = routing.generate('oro_email_mark_seen', { id: model.get('id'), status: status ? 0 : 1, checkThread: 0 }); model.set('seen', !status); Backbone.ajax({ type: 'GET', url: url, success: function(response) { if (_.result(response, 'successful') !== true) { model.set('seen', status); mediator.execute('showErrorMessage', __('Sorry, unexpected error was occurred'), 'error'); } }, error: function(xhr, err, message) { model.set('seen', status); mediator.execute('showErrorMessage', message, err); } }); }
var handleCreate = function(e) { e.preventDefault(); var routeName = urlParts.create.route; var routeParams = urlParts.create.parameters; var additionalRequestParams = selectorEl.data('select2_query_additional_params'); if (additionalRequestParams) { routeParams = $.extend({}, routeParams, additionalRequestParams); } var entityCreateDialog = new DialogWidget({ title: __('Create {{ entity }}', {'entity': label}), url: routing.generate(routeName, routeParams), stateEnabled: false, incrementalPosition: true, dialogOptions: { modal: true, allowMaximize: true, width: 1280, height: 650 } }); var processSelectedEntities = function(id) { selectorEl.inputWidget('val', id, true); entityCreateDialog.remove(); selectorEl.inputWidget('focus'); }; entityCreateDialog.on('formSave', _.bind(processSelectedEntities, this)); entityCreateDialog.render(); };
addToDashboard: function(data) { var wid = 'dashboard-widget-' + data.id; var containerId = 'widget-container-' + wid; var column = data.layout_position[0] ? data.layout_position[0] : 0; $('#dashboard-column-' + column).prepend($('<div id="' + containerId + '"></div>')); var state = { id: data.id, expanded: data.expanded, layoutPosition: data.layout_position }; var widgetParams = { widgetType: 'dashboard-item', wid: wid, url: routing.generate(data.config.route, _.extend(data.config.route_parameters, { _widgetId: state.id })), state: state, loadingMaskEnabled: false, container: '#' + containerId, allowEdit: this.options.allowEdit, showConfig: this.options.allowEdit && !_.isEmpty(data.config.configuration), widgetName: data.name, configurationDialogOptions: data.config.configuration_dialog_options }; var widget = new DashboardItemWidget(widgetParams); widget.render(); this.add(widget); if (this.options.allowEdit) { $(this.options.columnsSelector).sortable('refresh'); } },
onQuantityChange: function() { var self = this; var quantity = this.$quantity.val(); if (!this.isQuantityValueValid(quantity)) { return; } $.ajax({ url: routing.generate( this.options.matchOfferRoute, { id: this.options.quoteProductId, unit: this.$unitInput.val(), qty: quantity } ), type: 'GET', success: function(response) { if (!_.isEmpty(response)) { self.updateUnitPriceValue(String(response.price)); self.updateSelector(response.id); self.setValidAttribute(self.$quantity, true); self.updateSubtotals(); } else { self.updateUnitPriceValue(self.options.notAvailableMessage); self.setValidAttribute(self.$quantity, false); } } }); },
callEntryPoint: function(e) { var self = this; var $itemContainer = $(e.target).closest(this.options.selectors.itemContainer); var inputsSelector = ':input[data-ftid]'; _.each(this.options.excludeFields, function(field) { inputsSelector += self.options.excludeFilter.replace('{{name}}', field); }); var $formInputs = $itemContainer.closest('form').find(inputsSelector); var formData = $formInputs.serialize(); this.listenerOff(); this.$freightClassesSelect = $itemContainer.find(this.options.selectors.freightClassSelector); if (this.loadingMaskView) { this.loadingMaskView.dispose(); } this.loadingMaskView = new LoadingMaskView({container: this.$freightClassesSelect.closest('td')}); formData = formData + '&' + this.options.activeUnitCodeParam + '=' + encodeURI($itemContainer.find(this.options.selectors.unitSelect).val()); $.ajax({ url: routing.generate(this.options.routeFreightClassUpdate), type: 'post', data: formData, beforeSend: $.proxy(this._beforeSend, this), success: $.proxy(this._success, this), complete: $.proxy(this._complete, this), error: $.proxy(function(jqXHR) { this._dropValues(true); messenger.showErrorMessage(__(self.options.errorMessage), jqXHR.responseJSON); }, this) }); },
loadValuesById: function(successEventName) { var self = this; if (this.select2ConfigData === null) { $.ajax({ url: routing.generate( self.dictionaryValueRoute, { dictionary: this.dictionaryClass } ), data: { keys: this.value.value }, success: function(response) { self.trigger(successEventName, response); } }); } else { var select2ConfigData = this.select2ConfigData; var value = this.value.value; var result = { results: _.filter(select2ConfigData, function(item) { return _.indexOf(value, item.id) !== -1; }) }; self.trigger(successEventName, result); } },
loadRelatedData: function(accountUser) { var url = routing.generate(this.options.relatedDataRoute); var data = { account: accountUser.accountId, accountUser: accountUser.accountUserId }; var ajaxData = {}; if (this.options.formName) { ajaxData[this.options.formName] = data; } else { ajaxData = data; } mediator.trigger('quote:load:related-data'); $.ajax({ url: url, type: 'GET', data: ajaxData, success: function(response) { mediator.trigger('quote:loaded:related-data', response); }, error: function() { mediator.trigger('quote:loaded:related-data', {}); } }); },
onRowSelect: function(gridWidget, data) { var id = data.model.get('id'); var dialogWidgetName = this.options.dialogWidgetName; var contextTargetClass = this.contextView.currentTargetClass(); gridWidget._showLoading(); $.ajax({ url: routing.generate('oro_api_post_activity_relation', { activity: this.options.sourceEntityClassAlias, id: this.options.sourceEntityId }), type: 'POST', dataType: 'json', data: { targets: [{entity: contextTargetClass, id: id}] }, errorHandlerMessage: __('oro.ui.item_add_error') }).done(function() { messenger.notificationFlashMessage('success', __('oro.activity.contexts.added')); mediator.trigger('widget_success:activity_list:item:update'); mediator.trigger('widget:doRefresh:activity-context-activity-list-widget'); }).always(function() { gridWidget._hideLoading(); if (!dialogWidgetName) { return; } widgetManager.getWidgetInstanceByAlias(dialogWidgetName, function(dialogWidget) { dialogWidget.remove(); }); }); }
url: function(method, params) { return routing.generate(this.ROUTE[method], _.defaults({ entity: this.type, id: this.id, association: this.association }, params)); },
_renderCriteria: function() { var self = this; self.renderTemplate(); $.ajax({ url: routing.generate( 'oro_dictionary_value', { dictionary: this.dictionaryClass } ), data: { 'keys': this.value.value }, success: function(reposne) { self.value.value = reposne.results; self._writeDOMValue(self.value); self.applySelect2(); self.renderDeferred.resolve(); }, error: function(jqXHR) { messenger.showErrorMessage(__('Sorry, unexpected error was occurred'), jqXHR.responseJSON); } }); },
loadValuesById: function(successEventName) { var self = this; if (this.select2ConfigData === null) { $.ajax({ url: routing.generate( self.dictionaryValueRoute, { dictionary: this.dictionaryClass } ), data: { 'keys': this.value.value }, success: function(response) { self.trigger(successEventName, response); }, error: function(jqXHR) { messenger.showErrorMessage(__('Sorry, an unexpected error has occurred.'), jqXHR.responseJSON); } }); } else { var select2ConfigData = this.select2ConfigData; var value = this.value.value; var result = { results: _.filter(select2ConfigData, function(item) { return _.indexOf(value, item.id) !== -1; }) }; self.trigger(successEventName, result); } },
onUseAsDefault: function(e) { var self = this; var isDefault = 1; var defaultModel = this._getCurrentDefaultViewModel(); var gridName = this.gridName; var currentViewModel = this._getCurrentViewModel(); var id = currentViewModel.id; if (this._isCurrentViewSystem()) { // in this case we need to set default to false on current default view isDefault = 0; id = defaultModel.id; } return $.post( routing.generate('oro_datagrid_api_rest_gridview_default', { id: id, default: isDefault, gridName: gridName }), {}, function(response) { defaultModel.set({is_default: false}); currentViewModel.set({is_default: true}); self._showFlashMessage('success', __('oro.datagrid.gridView.updated')); } ).fail( function(response) { if (response.status === 404) { self._showFlashMessage('error', __('oro.datagrid.gridView.error.not_found')); } else { self._showFlashMessage('error', __('oro.ui.unexpected_error')); } } ); },
onSelect: function(node, selected) { if (this.initialization || !this.updateAllowed) { return; } var url = routing.generate('orob2b_cms_page_view', {id: selected.node.id}); mediator.execute('redirectTo', {url: url}); },
addressDeleteUrl: function() { var address = arguments[0]; return routing.generate( addressDeleteRoute.route, _.extend({addressId: address.get('id')}, addressDeleteRoute.params) ); }
onImportClick: function() { this._renderDialogWidget({ url: routing.generate(this.options.importRoute, $.extend({}, this.routeOptions)), dialogOptions: { title: this.options.importTitle } }); },
tags = _.map(tags, function(tag) { if (!tag.hasOwnProperty('url')) { tag.url = routing.generate('oro_tag_search', { id: tag.id }); } return tag; });
url: function () { var options = { relationId: this.relatedEntityId, relationClass: this.relatedEntityClassName, canCreate: this.canCreate, page: this.getPage() }; return routing.generate(this.route, options); },
function(widget) { widget.setUrl(routing.generate(self.options.widgetRoute, widgetParams)); if (data.widgetReload) { widget.render(); } else { mediator.trigger('datagrid:doRefresh:' + widgetParams.gridName); } }
mediator.once('page:afterChange', function() { messenger.notificationFlashMessage('success', __('Workflow saved.')); messenger.notificationFlashMessage( 'warning', __( 'oro.workflow.translation_rebuild_required', {path: routing.generate('oro_translation_translation_index')} ) ); });
onExportTemplateClick: function() { var exportTemplateUrl = routing.generate( this.options.exportTemplateRoute, $.extend({}, this.routeOptions, { processorAlias: this.options.exportTemplateProcessor }) ); window.open(exportTemplateUrl); },
url: function() { var param = { activity: this.get('activityClassAlias'), id: this.get('entityId'), entity: this.get('targetClassName'), entityId: this.get('targetId') }; return routing.generate('oro_api_delete_activity_relation', param); }
handleImportValidation: function() { this._renderImportDialogWidget({ url: routing.generate(this.options.importValidationRoute, $.extend({}, this.routeOptions)), dialogOptions: { title: this.options.importValidationTitle }, successMessage: __('oro.importexport.import_validation.success.message'), errorMessage: __('oro.importexport.import_validation.form_fail.message') }); },