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/CoreAdminHome/angularjs/branding/branding.controller.js')
-rw-r--r--plugins/CoreAdminHome/angularjs/branding/branding.controller.js108
1 files changed, 108 insertions, 0 deletions
diff --git a/plugins/CoreAdminHome/angularjs/branding/branding.controller.js b/plugins/CoreAdminHome/angularjs/branding/branding.controller.js
new file mode 100644
index 0000000000..97377941c0
--- /dev/null
+++ b/plugins/CoreAdminHome/angularjs/branding/branding.controller.js
@@ -0,0 +1,108 @@
+/*!
+ * Piwik - free/libre analytics platform
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ */
+
+/**
+ * Controller to save mail smtp settings
+ */
+(function () {
+ angular.module('piwikApp').controller('BrandingController', BrandingController);
+
+ BrandingController.$inject = ['$scope', 'piwikApi'];
+
+ function BrandingController($scope, piwikApi) {
+
+ var self = this;
+ this.isLoading = false;
+
+ function refreshCustomLogo() {
+ var selectors = ['#currentLogo', '#currentFavicon'];
+ var index;
+ for (index = 0; index < selectors.length; index++) {
+ var imageDiv = $(selectors[index]);
+ if (imageDiv && imageDiv.data("src") && imageDiv.data("srcExists")) {
+ var logoUrl = imageDiv.data("src");
+ imageDiv.attr("src", logoUrl + "?" + (new Date()).getTime());
+ imageDiv.show();
+ } else {
+ imageDiv.hide();
+ }
+ }
+ }
+
+ this.updateLogo = function () {
+ var isSubmittingLogo = (this.customLogo != undefined && this.customLogo != '');
+ var isSubmittingFavicon = (this.customFavicon != undefined && this.customFavicon != '');
+
+ if (!isSubmittingLogo && !isSubmittingFavicon) {
+ return;
+ }
+
+ var $uploadError = $('.uploaderror');
+ $uploadError.fadeOut();
+ var frameName = "upload" + (new Date()).getTime();
+ var uploadFrame = $("<iframe name=\"" + frameName + "\" />");
+ uploadFrame.css("display", "none");
+ uploadFrame.load(function (data) {
+ setTimeout(function () {
+ var frameContent = $(uploadFrame.contents()).find('body').html();
+ frameContent = $.trim(frameContent);
+
+ if ('0' === frameContent) {
+ $uploadError.show();
+ } else {
+ // Upload succeed, so we update the images availability
+ // according to what have been uploaded
+ if (isSubmittingLogo) {
+ $('#currentLogo').data("srcExists", true)
+ }
+ if (isSubmittingFavicon) {
+ $('#currentFavicon').data("srcExists", true)
+ }
+ refreshCustomLogo();
+ }
+
+ if ('1' === frameContent || '0' === frameContent) {
+ uploadFrame.remove();
+ }
+ }, 1000);
+ });
+ $("body:first").append(uploadFrame);
+ var submittingForm = $('#logoUploadForm');
+ submittingForm.attr("target", frameName);
+ submittingForm.submit();
+
+ this.customLogo = '';
+ this.customFavicon = '';
+ };
+
+ refreshCustomLogo();
+
+ this.toggleCustomLogo = function () {
+ refreshCustomLogo();
+ };
+
+ this.save = function () {
+
+ this.isLoading = true;
+
+ piwikApi.post({module: 'API', method: 'CoreAdminHome.setBrandingSettings'}, {
+ useCustomLogo: this.enabled ? '1' : '0'
+ }).then(function (success) {
+ self.isLoading = false;
+
+ var UI = require('piwik/UI');
+ var notification = new UI.Notification();
+ notification.show(_pk_translate('CoreAdminHome_SettingsSaveSuccess'), {
+ id: 'generalSettings', context: 'success'
+ });
+ notification.scrollToNotification();
+ }, function () {
+ self.isLoading = false;
+ });
+ };
+ }
+})(); \ No newline at end of file