Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/CustomDimensions/angularjs/manage/edit.controller.js')
m---------plugins/CustomDimensions0
-rw-r--r--plugins/CustomDimensions/angularjs/manage/edit.controller.js141
2 files changed, 141 insertions, 0 deletions
diff --git a/plugins/CustomDimensions b/plugins/CustomDimensions
deleted file mode 160000
-Subproject 318661a2fb1ef3b3e5d6d999ae8b9628cb5a113
diff --git a/plugins/CustomDimensions/angularjs/manage/edit.controller.js b/plugins/CustomDimensions/angularjs/manage/edit.controller.js
new file mode 100644
index 0000000000..39993b6545
--- /dev/null
+++ b/plugins/CustomDimensions/angularjs/manage/edit.controller.js
@@ -0,0 +1,141 @@
+/*!
+ * Matomo - free/libre analytics platform
+ *
+ * @link https://matomo.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+(function () {
+ angular.module('piwikApp').controller('CustomDimensionsEditController', CustomDimensionsEditController);
+
+ CustomDimensionsEditController.$inject = ['$scope', 'customDimensionsModel', 'piwik', '$location', '$filter'];
+
+ function CustomDimensionsEditController($scope, customDimensionsModel, piwik, $location, $filter) {
+
+ var self = this;
+ var currentId = null;
+ var notificationId = 'customdimensions';
+
+ var translate = $filter('translate');
+
+ this.model = customDimensionsModel;
+
+ function getNotification()
+ {
+ var UI = require('piwik/UI');
+ return new UI.Notification();
+ }
+
+ function removeAnyCustomDimensionNotification()
+ {
+ getNotification().remove(notificationId);
+ }
+
+ function showNotification(message, context)
+ {
+ var notification = getNotification();
+ notification.show(message, {context: context, id: notificationId});
+ }
+
+ function init(dimensionId)
+ {
+ self.create = dimensionId == '0';
+ self.edit = !(dimensionId == '0');
+
+ if (dimensionId !== null) {
+ removeAnyCustomDimensionNotification();
+ }
+
+ self.model.fetchCustomDimensionsConfiguration().then(function () {
+
+ if (self.edit && dimensionId) {
+ self.model.findCustomDimension(dimensionId).then(function (dimension) {
+ self.dimension = dimension;
+ if (dimension && !dimension.extractions.length) {
+ self.addExtraction();
+ }
+ });
+ } else if (self.create) {
+ self.dimension = {
+ idSite: piwik.idSite,
+ name: '',
+ active: false,
+ extractions: [],
+ scope: $scope.dimensionScope,
+ case_sensitive: true,
+ };
+ self.addExtraction();
+ }
+ });
+ }
+
+ this.removeExtraction = function(index)
+ {
+ if (index > -1) {
+ this.dimension.extractions.splice(index, 1);
+ }
+ };
+
+ this.addExtraction = function()
+ {
+ if (this.doesScopeSupportExtraction()) {
+ this.dimension.extractions.push({dimension: 'url', pattern: ''});
+ }
+ };
+
+ this.doesScopeSupportExtraction = function () {
+ if (!this.dimension || !this.dimension.scope || !this.model.availableScopes) {
+ return false;
+ }
+
+ var index, scope;
+ for (index in this.model.availableScopes) {
+ scope = this.model.availableScopes[index];
+ if (scope && scope.value === this.dimension.scope) {
+ return scope.supportsExtractions;
+ }
+ }
+
+ return false;
+ };
+
+ this.createCustomDimension = function () {
+ var method = 'CustomDimensions.configureNewCustomDimension';
+
+ this.isUpdating = true;
+
+ customDimensionsModel.createOrUpdateDimension(this.dimension, method).then(function (response) {
+ if (response.type === 'error') {
+ return;
+ }
+
+ showNotification(translate('CustomDimensions_DimensionCreated'), response.type);
+ self.model.reload();
+ $location.url('/list');
+ });
+ };
+
+ this.updateCustomDimension = function () {
+ this.dimension.idDimension = this.dimension.idcustomdimension;
+
+ var method = 'CustomDimensions.configureExistingCustomDimension';
+
+ this.isUpdating = true;
+
+ customDimensionsModel.createOrUpdateDimension(this.dimension, method).then(function (response) {
+ if (response.type === 'error') {
+ return;
+ }
+
+ showNotification(translate('CustomDimensions_DimensionUpdated'), response.type);
+ $location.url('/list');
+ });
+ };
+
+ $scope.$watch('dimensionId', function (newValue, oldValue) {
+ if (newValue != oldValue || currentId === null) {
+ currentId = newValue;
+ init(newValue);
+ }
+ });
+ }
+})(); \ No newline at end of file