PDF rausgenommen
This commit is contained in:
@ -0,0 +1,29 @@
|
||||
/*!
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
(function () {
|
||||
// can probably be shared
|
||||
angular.module('piwikApp').factory('coreAPI', CoreAPIFactory);
|
||||
|
||||
CoreAPIFactory.$inject = ['sitesManagerApiHelper'];
|
||||
|
||||
function CoreAPIFactory(api) {
|
||||
|
||||
return {
|
||||
getIpFromHeader: getIpFromHeader(),
|
||||
isPluginActivated: isPluginActivated()
|
||||
};
|
||||
|
||||
function getIpFromHeader() {
|
||||
return api.fetchApi('API.getIpFromHeader', api.valueAdaptor);
|
||||
}
|
||||
|
||||
function isPluginActivated() {
|
||||
return api.fetchApi('API.isPluginActivated', api.valueAdaptor);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
@ -0,0 +1,74 @@
|
||||
/*!
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
(function () {
|
||||
// can probably be renamed and shared
|
||||
angular.module('piwikApp').factory('sitesManagerApiHelper', SitesManagerAPIHelperFactory);
|
||||
|
||||
SitesManagerAPIHelperFactory.$inject = ['piwikApi'];
|
||||
|
||||
function SitesManagerAPIHelperFactory(piwikApi) {
|
||||
|
||||
return {
|
||||
fetch: fetch,
|
||||
commaDelimitedFieldToArray: commaDelimitedFieldToArray,
|
||||
fetchApi: fetchApi,
|
||||
fetchAction: fetchAction,
|
||||
singleObjectAdaptor: singleObjectAdaptor,
|
||||
valueAdaptor: valueAdaptor,
|
||||
noop: noop
|
||||
};
|
||||
|
||||
function fetch (endpoint, jsonResponseAdaptor, params) {
|
||||
|
||||
return function (clientHandover, additionalParams) {
|
||||
|
||||
params = angular.extend(params || {}, additionalParams || {});
|
||||
|
||||
var requestDefinition = angular.extend(endpoint, params);
|
||||
|
||||
var responseHandler = function (response) {
|
||||
|
||||
response = jsonResponseAdaptor(response);
|
||||
|
||||
clientHandover(response);
|
||||
};
|
||||
|
||||
piwikApi.fetch(requestDefinition).then(responseHandler);
|
||||
};
|
||||
}
|
||||
|
||||
function commaDelimitedFieldToArray (value) {
|
||||
|
||||
if(!value)
|
||||
return [];
|
||||
|
||||
return value.split(',');
|
||||
}
|
||||
|
||||
function fetchApi(apiMethod, jsonResponseAdaptor, params) {
|
||||
|
||||
return fetch({method: apiMethod}, jsonResponseAdaptor, params);
|
||||
}
|
||||
|
||||
function fetchAction(module, action, jsonResponseAdaptor, params) {
|
||||
|
||||
return fetch({module: module, action: action}, jsonResponseAdaptor, params);
|
||||
}
|
||||
|
||||
function singleObjectAdaptor(response) {
|
||||
return response[0];
|
||||
}
|
||||
|
||||
function valueAdaptor(response) {
|
||||
return response.value;
|
||||
}
|
||||
|
||||
function noop(response) {
|
||||
return response;
|
||||
}
|
||||
}
|
||||
})();
|
@ -0,0 +1,44 @@
|
||||
/*!
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
(function () {
|
||||
angular.module('piwikApp').factory('sitesManagerAPI', SitesManagerAPIFactory);
|
||||
|
||||
SitesManagerAPIFactory.$inject = ['sitesManagerApiHelper'];
|
||||
|
||||
function SitesManagerAPIFactory(api) {
|
||||
|
||||
return {
|
||||
getCurrencyList: getCurrencyList(),
|
||||
getTimezonesList: getTimezonesList(),
|
||||
isTimezoneSupportEnabled: isTimezoneSupportEnabled(),
|
||||
getGlobalSettings: getGlobalSettings(),
|
||||
getSitesIdWithAdminAccess: getSitesIdWithAdminAccess()
|
||||
};
|
||||
|
||||
function getSitesIdWithAdminAccess () {
|
||||
return api.fetchApi('SitesManager.getSitesIdWithAdminAccess', api.noop, {
|
||||
filter_limit: '-1',
|
||||
});
|
||||
}
|
||||
function getCurrencyList () {
|
||||
return api.fetchApi('SitesManager.getCurrencyList', api.noop);
|
||||
}
|
||||
|
||||
function getTimezonesList () {
|
||||
return api.fetchApi('SitesManager.getTimezonesList', api.noop);
|
||||
}
|
||||
|
||||
function isTimezoneSupportEnabled () {
|
||||
return api.fetchApi('SitesManager.isTimezoneSupportEnabled', api.valueAdaptor);
|
||||
}
|
||||
|
||||
function getGlobalSettings () {
|
||||
return api.fetchAction('SitesManager', 'getGlobalSettings', api.noop);
|
||||
}
|
||||
}
|
||||
|
||||
})();
|
@ -0,0 +1,30 @@
|
||||
/*!
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
(function () {
|
||||
angular.module('piwikApp').directive('sitesManagerEditTrigger', sitesManagerEditTrigger);
|
||||
|
||||
function sitesManagerEditTrigger() {
|
||||
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function (scope, element) {
|
||||
|
||||
element.bind('click', function(){
|
||||
|
||||
if(!scope.site.editMode)
|
||||
scope.$apply(scope.editSite());
|
||||
});
|
||||
|
||||
scope.$watch('site.editMode', function() {
|
||||
|
||||
element.toggleClass('editable-site-field', !scope.site.editMode);
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
})();
|
@ -0,0 +1,6 @@
|
||||
<textarea
|
||||
cols="{{ cols }}"
|
||||
rows="{{ rows }}"
|
||||
ng-model="field.value"
|
||||
ng-change="onChange()">
|
||||
</textarea>
|
@ -0,0 +1,49 @@
|
||||
/*!
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
(function () {
|
||||
angular.module('piwikApp').directive('sitesManagerMultilineField', sitesManagerMultilineField);
|
||||
|
||||
function sitesManagerMultilineField() {
|
||||
|
||||
return {
|
||||
restrict: 'A',
|
||||
replace: true,
|
||||
scope: {
|
||||
managedValue: '=field',
|
||||
rows: '@?',
|
||||
cols: '@?'
|
||||
},
|
||||
templateUrl: 'plugins/SitesManager/angularjs/sites-manager/multiline-field.directive.html?cb=' + piwik.cacheBuster,
|
||||
link: function (scope) {
|
||||
|
||||
var separator = '\n';
|
||||
|
||||
var init = function () {
|
||||
|
||||
scope.field = {};
|
||||
scope.onChange = updateManagedScopeValue;
|
||||
|
||||
scope.$watch('managedValue', updateInputValue);
|
||||
};
|
||||
|
||||
var updateManagedScopeValue = function () {
|
||||
scope.managedValue = scope.field.value.trim().split(separator);
|
||||
};
|
||||
|
||||
var updateInputValue = function () {
|
||||
|
||||
if(angular.isUndefined(scope.managedValue))
|
||||
return;
|
||||
|
||||
scope.field.value = scope.managedValue.join(separator);
|
||||
};
|
||||
|
||||
init();
|
||||
}
|
||||
};
|
||||
}
|
||||
})();
|
115
msd2/tracking/piwik/plugins/SitesManager/angularjs/sites-manager/sites-manager-admin-sites-model.js
vendored
Normal file
115
msd2/tracking/piwik/plugins/SitesManager/angularjs/sites-manager/sites-manager-admin-sites-model.js
vendored
Normal file
@ -0,0 +1,115 @@
|
||||
/**
|
||||
* Model for Sites Manager. Fetches only sites one has at least Admin permission.
|
||||
*/
|
||||
(function () {
|
||||
angular.module('piwikApp').factory('sitesManagerAdminSitesModel', sitesManagerAdminSitesModel);
|
||||
|
||||
sitesManagerAdminSitesModel.$inject = ['piwikApi'];
|
||||
|
||||
function sitesManagerAdminSitesModel(piwikApi)
|
||||
{
|
||||
var model = {
|
||||
sites : [],
|
||||
searchTerm : '',
|
||||
isLoading : false,
|
||||
pageSize : 10,
|
||||
currentPage : 0,
|
||||
offsetStart : 0,
|
||||
offsetEnd : 10,
|
||||
hasPrev : false,
|
||||
hasNext : false,
|
||||
previousPage: previousPage,
|
||||
nextPage: nextPage,
|
||||
searchSite: searchSite,
|
||||
fetchLimitedSitesWithAdminAccess: fetchLimitedSitesWithAdminAccess
|
||||
};
|
||||
|
||||
return model;
|
||||
|
||||
function onError ()
|
||||
{
|
||||
setSites([]);
|
||||
}
|
||||
|
||||
function setSites(sites)
|
||||
{
|
||||
model.sites = sites;
|
||||
|
||||
var numSites = sites.length;
|
||||
model.offsetStart = model.currentPage * model.pageSize + 1;
|
||||
model.offsetEnd = model.offsetStart + numSites - 1;
|
||||
model.hasPrev = model.currentPage >= 1;
|
||||
model.hasNext = numSites === model.pageSize;
|
||||
}
|
||||
|
||||
function setCurrentPage(page)
|
||||
{
|
||||
if (page < 0) {
|
||||
page = 0;
|
||||
}
|
||||
|
||||
model.currentPage = page;
|
||||
}
|
||||
|
||||
function previousPage()
|
||||
{
|
||||
setCurrentPage(model.currentPage - 1);
|
||||
fetchLimitedSitesWithAdminAccess();
|
||||
}
|
||||
|
||||
function nextPage()
|
||||
{
|
||||
setCurrentPage(model.currentPage + 1);
|
||||
fetchLimitedSitesWithAdminAccess();
|
||||
}
|
||||
|
||||
function searchSite (term)
|
||||
{
|
||||
model.searchTerm = term;
|
||||
setCurrentPage(0);
|
||||
fetchLimitedSitesWithAdminAccess();
|
||||
}
|
||||
|
||||
function fetchLimitedSitesWithAdminAccess(callback)
|
||||
{
|
||||
if (model.isLoading) {
|
||||
piwikApi.abort();
|
||||
}
|
||||
|
||||
model.isLoading = true;
|
||||
|
||||
var limit = model.pageSize;
|
||||
var offset = model.currentPage * model.pageSize;
|
||||
|
||||
var params = {
|
||||
method: 'SitesManager.getSitesWithAdminAccess',
|
||||
fetchAliasUrls: true,
|
||||
limit: limit + offset, // this is applied in SitesManager.getSitesWithAdminAccess API
|
||||
filter_offset: offset, // filter_offset and filter_limit is applied in response builder
|
||||
filter_limit: limit
|
||||
};
|
||||
|
||||
if (model.searchTerm) {
|
||||
params.pattern = model.searchTerm;
|
||||
}
|
||||
|
||||
return piwikApi.fetch(params).then(function (sites) {
|
||||
|
||||
if (!sites) {
|
||||
onError();
|
||||
return;
|
||||
}
|
||||
|
||||
setSites(sites);
|
||||
|
||||
}, onError).finally(function () {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
|
||||
model.isLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
})();
|
@ -0,0 +1,226 @@
|
||||
/*!
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
(function () {
|
||||
angular.module('piwikApp').controller('SitesManagerSiteController', SitesManagerSiteController);
|
||||
|
||||
SitesManagerSiteController.$inject = ['$scope', '$filter', 'sitesManagerApiHelper', 'sitesManagerTypeModel', 'piwikApi', '$timeout'];
|
||||
|
||||
function SitesManagerSiteController($scope, $filter, sitesManagerApiHelper, sitesManagerTypeModel, piwikApi, $timeout) {
|
||||
|
||||
var translate = $filter('translate');
|
||||
|
||||
var updateView = function () {
|
||||
$timeout(function () {
|
||||
$('.editingSite').find('select').material_select();
|
||||
Materialize.updateTextFields();
|
||||
});
|
||||
}
|
||||
|
||||
var init = function () {
|
||||
|
||||
initModel();
|
||||
initActions();
|
||||
|
||||
$scope.site.isLoading = true;
|
||||
sitesManagerTypeModel.fetchTypeById($scope.site.type).then(function (type) {
|
||||
$scope.site.isLoading = false;
|
||||
|
||||
if (type) {
|
||||
$scope.currentType = type;
|
||||
$scope.howToSetupUrl = type.howToSetupUrl;
|
||||
$scope.isInternalSetupUrl = '?' === ('' + type.howToSetupUrl).substr(0, 1);
|
||||
$scope.typeSettings = type.settings;
|
||||
|
||||
if (isSiteNew()) {
|
||||
$scope.measurableSettings = angular.copy(type.settings);
|
||||
}
|
||||
} else {
|
||||
$scope.currentType = {name: $scope.site.type};
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var initActions = function () {
|
||||
|
||||
$scope.editSite = editSite;
|
||||
$scope.saveSite = saveSite;
|
||||
$scope.openDeleteDialog = openDeleteDialog;
|
||||
$scope.site['delete'] = deleteSite;
|
||||
};
|
||||
|
||||
var initModel = function() {
|
||||
|
||||
if (isSiteNew()) {
|
||||
initNewSite();
|
||||
} else {
|
||||
$scope.site.excluded_ips = sitesManagerApiHelper.commaDelimitedFieldToArray($scope.site.excluded_ips);
|
||||
$scope.site.excluded_parameters = sitesManagerApiHelper.commaDelimitedFieldToArray($scope.site.excluded_parameters);
|
||||
$scope.site.excluded_user_agents = sitesManagerApiHelper.commaDelimitedFieldToArray($scope.site.excluded_user_agents);
|
||||
$scope.site.sitesearch_keyword_parameters = sitesManagerApiHelper.commaDelimitedFieldToArray($scope.site.sitesearch_keyword_parameters);
|
||||
$scope.site.sitesearch_category_parameters = sitesManagerApiHelper.commaDelimitedFieldToArray($scope.site.sitesearch_category_parameters);
|
||||
}
|
||||
|
||||
$scope.site.removeDialog = {};
|
||||
|
||||
updateView();
|
||||
};
|
||||
|
||||
var editSite = function () {
|
||||
$scope.site.editMode = true;
|
||||
|
||||
$scope.measurableSettings = [];
|
||||
$scope.site.isLoading = true;
|
||||
piwikApi.fetch({method: 'SitesManager.getSiteSettings', idSite: $scope.site.idsite}).then(function (settings) {
|
||||
$scope.measurableSettings = settings;
|
||||
$scope.site.isLoading = false;
|
||||
}, function () {
|
||||
$scope.site.isLoading = false;
|
||||
});
|
||||
|
||||
updateView();
|
||||
};
|
||||
|
||||
var saveSite = function() {
|
||||
|
||||
var sendSiteSearchKeywordParams = $scope.site.sitesearch == '1' && !$scope.site.useDefaultSiteSearchParams;
|
||||
var sendSearchCategoryParameters = sendSiteSearchKeywordParams && $scope.customVariablesActivated;
|
||||
|
||||
var values = {
|
||||
siteName: $scope.site.name,
|
||||
timezone: $scope.site.timezone,
|
||||
currency: $scope.site.currency,
|
||||
type: $scope.site.type,
|
||||
settingValues: {}
|
||||
};
|
||||
|
||||
var isNewSite = isSiteNew();
|
||||
|
||||
var apiMethod = 'SitesManager.addSite';
|
||||
if (!isNewSite) {
|
||||
apiMethod = 'SitesManager.updateSite';
|
||||
values.idSite = $scope.site.idsite;
|
||||
}
|
||||
|
||||
angular.forEach($scope.measurableSettings, function (settings) {
|
||||
if (!values['settingValues'][settings.pluginName]) {
|
||||
values['settingValues'][settings.pluginName] = [];
|
||||
}
|
||||
|
||||
angular.forEach(settings.settings, function (setting) {
|
||||
var value = setting.value;
|
||||
if (value === false) {
|
||||
value = '0';
|
||||
} else if (value === true) {
|
||||
value = '1';
|
||||
}
|
||||
if (angular.isArray(value) && setting.uiControl == 'textarea') {
|
||||
var newValue = [];
|
||||
angular.forEach(value, function (val) {
|
||||
// as they are line separated we cannot trim them in the view
|
||||
if (val) {
|
||||
newValue.push(val);
|
||||
}
|
||||
});
|
||||
value = newValue;
|
||||
}
|
||||
|
||||
values['settingValues'][settings.pluginName].push({
|
||||
name: setting.name,
|
||||
value: value
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
piwikApi.post({method: apiMethod}, values).then(function (response) {
|
||||
$scope.site.editMode = false;
|
||||
|
||||
var UI = require('piwik/UI');
|
||||
var notification = new UI.Notification();
|
||||
|
||||
var message = 'Website updated';
|
||||
if (isNewSite) {
|
||||
message = 'Website created';
|
||||
}
|
||||
|
||||
notification.show(message, {context: 'success', id: 'websitecreated'});
|
||||
notification.scrollToNotification();
|
||||
|
||||
if (!$scope.site.idsite && response && response.value) {
|
||||
$scope.site.idsite = response.value;
|
||||
}
|
||||
|
||||
angular.forEach(values.settingValues, function (settings, pluginName) {
|
||||
angular.forEach(settings, function (setting) {
|
||||
if (setting.name === 'urls') {
|
||||
$scope.site.alias_urls = setting.value;
|
||||
} else {
|
||||
$scope.site[setting.name] = setting.value;
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var isSiteNew = function() {
|
||||
return angular.isUndefined($scope.site.idsite);
|
||||
};
|
||||
|
||||
var initNewSite = function() {
|
||||
$scope.site.editMode = true;
|
||||
$scope.site.timezone = $scope.globalSettings.defaultTimezone;
|
||||
$scope.site.currency = $scope.globalSettings.defaultCurrency;
|
||||
|
||||
if ($scope.typeSettings) {
|
||||
// we do not want to manipulate initial type settings
|
||||
$scope.measurableSettings = angular.copy($scope.typeSettings);
|
||||
}
|
||||
};
|
||||
|
||||
var openDeleteDialog = function() {
|
||||
|
||||
$scope.site.removeDialog.title = translate('SitesManager_DeleteConfirm', '"' + $scope.site.name + '" (idSite = ' + $scope.site.idsite + ')');
|
||||
$scope.site.removeDialog.show = true;
|
||||
};
|
||||
|
||||
var deleteSite = function() {
|
||||
var redirectParams = $scope.redirectParams;
|
||||
|
||||
// if the current idSite in the URL is the site we're deleting, then we have to make to change it. otherwise,
|
||||
// if a user goes to another page, the invalid idSite may cause a fatal error.
|
||||
if (broadcast.getValueFromUrl('idSite') == $scope.site.idsite) {
|
||||
var sites = $scope.adminSites.sites;
|
||||
|
||||
var otherSite;
|
||||
for (var i = 0; i !== sites.length; ++i) {
|
||||
if (sites[i].idsite != $scope.site.idsite) {
|
||||
otherSite = sites[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (otherSite) {
|
||||
redirectParams = $.extend({}, redirectParams, { idSite: otherSite.idsite });
|
||||
}
|
||||
}
|
||||
|
||||
var ajaxHandler = new ajaxHelper();
|
||||
|
||||
ajaxHandler.addParams({
|
||||
idSite: $scope.site.idsite,
|
||||
module: 'API',
|
||||
format: 'json',
|
||||
method: 'SitesManager.deleteSite'
|
||||
}, 'GET');
|
||||
|
||||
ajaxHandler.redirectOnSuccess(redirectParams);
|
||||
ajaxHandler.setLoadingElement();
|
||||
ajaxHandler.send();
|
||||
};
|
||||
|
||||
init();
|
||||
}
|
||||
})();
|
52
msd2/tracking/piwik/plugins/SitesManager/angularjs/sites-manager/sites-manager-type-model.js
vendored
Normal file
52
msd2/tracking/piwik/plugins/SitesManager/angularjs/sites-manager/sites-manager-type-model.js
vendored
Normal file
@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Model for Sites Manager. Fetches only sites one has at least Admin permission.
|
||||
*/
|
||||
(function () {
|
||||
angular.module('piwikApp').factory('sitesManagerTypeModel', sitesManagerTypeModel);
|
||||
|
||||
sitesManagerTypeModel.$inject = ['piwikApi'];
|
||||
|
||||
function sitesManagerTypeModel(piwikApi)
|
||||
{
|
||||
var typesPromise = null;
|
||||
|
||||
var model = {
|
||||
typesById: {},
|
||||
fetchTypeById: fetchTypeById,
|
||||
fetchAvailableTypes: fetchAvailableTypes,
|
||||
hasMultipleTypes: hasMultipleTypes
|
||||
};
|
||||
|
||||
return model;
|
||||
|
||||
function hasMultipleTypes(typeId)
|
||||
{
|
||||
return fetchAvailableTypes().then(function (types) {
|
||||
return types && types.length > 1;
|
||||
});
|
||||
}
|
||||
|
||||
function fetchTypeById(typeId)
|
||||
{
|
||||
return fetchAvailableTypes().then(function () {
|
||||
return model.typesById[typeId];
|
||||
});
|
||||
}
|
||||
|
||||
function fetchAvailableTypes()
|
||||
{
|
||||
if (!typesPromise) {
|
||||
typesPromise = piwikApi.fetch({method: 'API.getAvailableMeasurableTypes', filter_limit: '-1'}).then(function (types) {
|
||||
|
||||
angular.forEach(types, function (type) {
|
||||
model.typesById[type.id] = type;
|
||||
});
|
||||
|
||||
return types;
|
||||
});
|
||||
}
|
||||
|
||||
return typesPromise;
|
||||
}
|
||||
}
|
||||
})();
|
@ -0,0 +1,277 @@
|
||||
/*!
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
(function () {
|
||||
angular.module('piwikApp').controller('SitesManagerController', SitesManagerController);
|
||||
|
||||
SitesManagerController.$inject = ['$scope', '$filter', 'coreAPI', 'sitesManagerAPI', 'piwikApi', 'sitesManagerAdminSitesModel', 'piwik', 'sitesManagerApiHelper', 'sitesManagerTypeModel', '$rootScope', '$window'];
|
||||
|
||||
function SitesManagerController($scope, $filter, coreAPI, sitesManagerAPI, piwikApi, adminSites, piwik, sitesManagerApiHelper, sitesManagerTypeModel, $rootScope, $window) {
|
||||
|
||||
var translate = $filter('translate');
|
||||
|
||||
$scope.globalSettings = {};
|
||||
|
||||
$rootScope.$on('$locationChangeSuccess', function () {
|
||||
if (piwik.hasSuperUserAccess) {
|
||||
// as we are not using a router yet...
|
||||
if ($window.location.hash === '#globalSettings' || $window.location.hash === '#/globalSettings') {
|
||||
broadcast.propagateNewPage('action=globalSettings');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var init = function () {
|
||||
|
||||
$scope.period = piwik.broadcast.getValueFromUrl('period');
|
||||
$scope.date = piwik.broadcast.getValueFromUrl('date');
|
||||
$scope.adminSites = adminSites;
|
||||
$scope.hasSuperUserAccess = piwik.hasSuperUserAccess;
|
||||
$scope.redirectParams = {showaddsite: false};
|
||||
$scope.cacheBuster = piwik.cacheBuster;
|
||||
$scope.totalNumberOfSites = '?';
|
||||
|
||||
initSelectLists();
|
||||
initUtcTime();
|
||||
initUserIP();
|
||||
initCustomVariablesActivated();
|
||||
initIsTimezoneSupportEnabled();
|
||||
initGlobalParams();
|
||||
|
||||
initActions();
|
||||
};
|
||||
|
||||
var initActions = function () {
|
||||
|
||||
$scope.cancelEditSite = cancelEditSite;
|
||||
$scope.addSite = addSite;
|
||||
$scope.addNewEntity = addNewEntity;
|
||||
$scope.saveGlobalSettings = saveGlobalSettings;
|
||||
$scope.lookupCurrentEditSite = lookupCurrentEditSite;
|
||||
};
|
||||
|
||||
var initAvailableTypes = function () {
|
||||
return sitesManagerTypeModel.fetchAvailableTypes().then(function (types) {
|
||||
$scope.availableTypes = types;
|
||||
$scope.typeForNewEntity = 'website';
|
||||
|
||||
return types;
|
||||
});
|
||||
};
|
||||
|
||||
var initSelectLists = function() {
|
||||
|
||||
initCurrencyList();
|
||||
initTimezones();
|
||||
};
|
||||
|
||||
var initGlobalParams = function() {
|
||||
|
||||
showLoading();
|
||||
|
||||
var availableTypesPromise = initAvailableTypes();
|
||||
|
||||
sitesManagerAPI.getGlobalSettings(function(globalSettings) {
|
||||
|
||||
$scope.globalSettings = globalSettings;
|
||||
|
||||
$scope.globalSettings.searchKeywordParametersGlobal = sitesManagerApiHelper.commaDelimitedFieldToArray($scope.globalSettings.searchKeywordParametersGlobal);
|
||||
$scope.globalSettings.searchCategoryParametersGlobal = sitesManagerApiHelper.commaDelimitedFieldToArray($scope.globalSettings.searchCategoryParametersGlobal);
|
||||
$scope.globalSettings.excludedIpsGlobal = sitesManagerApiHelper.commaDelimitedFieldToArray($scope.globalSettings.excludedIpsGlobal);
|
||||
$scope.globalSettings.excludedQueryParametersGlobal = sitesManagerApiHelper.commaDelimitedFieldToArray($scope.globalSettings.excludedQueryParametersGlobal);
|
||||
$scope.globalSettings.excludedUserAgentsGlobal = sitesManagerApiHelper.commaDelimitedFieldToArray($scope.globalSettings.excludedUserAgentsGlobal);
|
||||
|
||||
hideLoading();
|
||||
|
||||
initKeepURLFragmentsList();
|
||||
|
||||
adminSites.fetchLimitedSitesWithAdminAccess(function () {
|
||||
availableTypesPromise.then(function () {
|
||||
triggerAddSiteIfRequested();
|
||||
});
|
||||
});
|
||||
sitesManagerAPI.getSitesIdWithAdminAccess(function (siteIds) {
|
||||
if (siteIds && siteIds.length) {
|
||||
$scope.totalNumberOfSites = siteIds.length;
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var triggerAddSiteIfRequested = function() {
|
||||
var search = String(window.location.search);
|
||||
|
||||
if(piwik.helper.getArrayFromQueryString(search).showaddsite == 1)
|
||||
addNewEntity();
|
||||
};
|
||||
|
||||
var initUtcTime = function() {
|
||||
|
||||
var currentDate = new Date();
|
||||
|
||||
$scope.utcTime = new Date(
|
||||
currentDate.getUTCFullYear(),
|
||||
currentDate.getUTCMonth(),
|
||||
currentDate.getUTCDate(),
|
||||
currentDate.getUTCHours(),
|
||||
currentDate.getUTCMinutes(),
|
||||
currentDate.getUTCSeconds()
|
||||
);
|
||||
};
|
||||
|
||||
var initIsTimezoneSupportEnabled = function() {
|
||||
|
||||
sitesManagerAPI.isTimezoneSupportEnabled(function (timezoneSupportEnabled) {
|
||||
$scope.timezoneSupportEnabled = timezoneSupportEnabled;
|
||||
});
|
||||
};
|
||||
|
||||
var initTimezones = function() {
|
||||
|
||||
sitesManagerAPI.getTimezonesList(
|
||||
|
||||
function (timezones) {
|
||||
|
||||
var scopeTimezones = [];
|
||||
$scope.timezones = [];
|
||||
|
||||
angular.forEach(timezones, function(groupTimezones, timezoneGroup) {
|
||||
|
||||
angular.forEach(groupTimezones, function(label, code) {
|
||||
|
||||
scopeTimezones.push({
|
||||
group: timezoneGroup,
|
||||
key: code,
|
||||
value: label
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
$scope.timezones = scopeTimezones;
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
var initCustomVariablesActivated = function() {
|
||||
|
||||
coreAPI.isPluginActivated(
|
||||
|
||||
function (customVariablesActivated) {
|
||||
$scope.customVariablesActivated = customVariablesActivated;
|
||||
},
|
||||
|
||||
{pluginName: 'CustomVariables'}
|
||||
);
|
||||
};
|
||||
|
||||
var initUserIP = function() {
|
||||
|
||||
coreAPI.getIpFromHeader(function(ip) {
|
||||
$scope.currentIpAddress = ip;
|
||||
});
|
||||
};
|
||||
|
||||
var initKeepURLFragmentsList = function() {
|
||||
$scope.keepURLFragmentsOptions = [
|
||||
{key: 0, value: ($scope.globalSettings.keepURLFragmentsGlobal ? translate('General_Yes') : translate('General_No')) + ' (' + translate('General_Default') + ')'},
|
||||
{key: 1, value: translate('General_Yes')},
|
||||
{key: 2, value: translate('General_No')}
|
||||
];
|
||||
};
|
||||
|
||||
var addNewEntity = function () {
|
||||
sitesManagerTypeModel.hasMultipleTypes().then(function (hasMultipleTypes) {
|
||||
if (hasMultipleTypes) {
|
||||
$scope.showAddSiteDialog = true;
|
||||
} else if ($scope.availableTypes.length === 1) {
|
||||
var type = $scope.availableTypes[0].id;
|
||||
addSite(type);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
var addSite = function(type) {
|
||||
|
||||
var parameters = {isAllowed: true, measurableType: type};
|
||||
$rootScope.$emit('SitesManager.initAddSite', parameters);
|
||||
if (parameters && !parameters.isAllowed) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!type) {
|
||||
type = 'website'; // todo shall we really hard code this or trigger an exception or so?
|
||||
}
|
||||
|
||||
$scope.adminSites.sites.unshift({type: type});
|
||||
};
|
||||
|
||||
var saveGlobalSettings = function() {
|
||||
|
||||
var ajaxHandler = new ajaxHelper();
|
||||
|
||||
ajaxHandler.addParams({
|
||||
module: 'SitesManager',
|
||||
format: 'json',
|
||||
action: 'setGlobalSettings'
|
||||
}, 'GET');
|
||||
|
||||
ajaxHandler.addParams({
|
||||
timezone: $scope.globalSettings.defaultTimezone,
|
||||
currency: $scope.globalSettings.defaultCurrency,
|
||||
excludedIps: $scope.globalSettings.excludedIpsGlobal.join(','),
|
||||
excludedQueryParameters: $scope.globalSettings.excludedQueryParametersGlobal.join(','),
|
||||
excludedUserAgents: $scope.globalSettings.excludedUserAgentsGlobal.join(','),
|
||||
keepURLFragments: $scope.globalSettings.keepURLFragmentsGlobal ? 1 : 0,
|
||||
enableSiteUserAgentExclude: $scope.globalSettings.siteSpecificUserAgentExcludeEnabled ? 1 : 0,
|
||||
searchKeywordParameters: $scope.globalSettings.searchKeywordParametersGlobal.join(','),
|
||||
searchCategoryParameters: $scope.globalSettings.searchCategoryParametersGlobal.join(',')
|
||||
}, 'POST');
|
||||
ajaxHandler.withTokenInUrl();
|
||||
ajaxHandler.redirectOnSuccess($scope.redirectParams);
|
||||
ajaxHandler.setLoadingElement();
|
||||
ajaxHandler.send();
|
||||
};
|
||||
|
||||
var cancelEditSite = function (site) {
|
||||
site.editMode = false;
|
||||
|
||||
var idSite = site.idsite;
|
||||
if (idSite) {
|
||||
var siteElement = $('.site[idsite=' + idSite + ']');
|
||||
if (siteElement[0]) {
|
||||
// todo move this into a directive
|
||||
siteElement[0].scrollIntoView();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
var lookupCurrentEditSite = function () {
|
||||
|
||||
var sitesInEditMode = $scope.adminSites.sites.filter(function(site) {
|
||||
return site.editMode;
|
||||
});
|
||||
|
||||
return sitesInEditMode[0];
|
||||
};
|
||||
|
||||
var initCurrencyList = function () {
|
||||
|
||||
sitesManagerAPI.getCurrencyList(function (currencies) {
|
||||
$scope.currencies = currencies;
|
||||
});
|
||||
};
|
||||
|
||||
var showLoading = function() {
|
||||
$scope.loading = true;
|
||||
};
|
||||
|
||||
var hideLoading = function() {
|
||||
$scope.loading = false;
|
||||
};
|
||||
|
||||
init();
|
||||
}
|
||||
})();
|
Reference in New Issue
Block a user