Lemonldap-NG-Manager
view release on metacpan or search on metacpan
site/htdocs/static/js/viewer.js view on Meta::CPAN
(function () {
'use strict';
/*
LemonLDAP::NG Viewer client
This is the main app file. Other are:
- struct.json and js/confTree.js that contains the full tree
- translate.json that contains the keywords translation
This file contains:
- the AngularJS controller
*/
var llapp;
llapp = angular.module('llngViewer', ['ui.tree', 'ui.bootstrap', 'llApp', 'ngCookies']);
/*
Main AngularJS controller
*/
llapp.controller('TreeCtrl', ['$scope', '$http', '$location', '$q', '$uibModal', '$translator', '$cookies', '$htmlParams', '$timeout', function ($scope, $http, $location, $q, $uibModal, $translator, $cookies, $htmlParams, $timeout) {
var _download, _stoggle, c, id, pathEvent, readError, setHelp;
$scope.links = window.links;
$scope.menu = $htmlParams.menu;
$scope.menulinks = window.menulinks;
$scope.staticPrefix = window.staticPrefix;
$scope.formPrefix = window.formPrefix;
$scope.availableLanguages = window.availableLanguages;
$scope.waiting = true;
$scope.showM = false;
$scope.showT = false;
$scope.form = 'homeViewer';
$scope.currentCfg = {};
$scope.clipboardAvailable = Boolean(navigator.clipboard);
$scope.viewPrefix = window.viewPrefix;
$scope.allowDiff = window.allowDiff;
$scope.message = {};
$scope.result = '';
// Import translations functions
$scope.translateTitle = function (node) {
return $translator.translateField(node, 'title');
};
$scope.translateP = $translator.translateP;
$scope.translate = $translator.translate;
// HELP DISPLAY
$scope.helpUrl = 'start.html#configuration';
$scope.setShowHelp = function (val) {
var d;
if (val == null) {
val = !$scope.showH;
}
$scope.showH = val;
d = new Date(Date.now());
d.setFullYear(d.getFullYear() + 1);
return $cookies.put('showhelp', val ? 'true' : 'false', {
"expires": d
});
};
$scope.showH = $cookies.get('showhelp') === 'false' ? false : true;
if ($scope.showH == null) {
$scope.setShowHelp(true);
}
// INTERCEPT AJAX ERRORS
readError = function (response) {
var e, j;
e = response.status;
j = response.statusLine;
$scope.waiting = false;
if (e === 403) {
$scope.message = {
title: 'forbidden',
message: '',
items: []
};
} else if (e === 401) {
console.debug('Authentication needed');
$scope.message = {
title: 'authenticationNeeded',
message: '__waitOrF5__',
items: []
};
} else if (e === 400) {
$scope.message = {
title: 'badRequest',
message: j,
items: []
};
} else if (e > 0) {
$scope.message = {
title: 'badRequest',
message: j,
items: []
};
} else {
site/htdocs/static/js/viewer.js view on Meta::CPAN
var node;
node = scope.$modelValue;
return _download(node);
};
_download = function (node) {
var d, uri;
d = $q.defer();
d.notify('Trying to get datas');
$scope.waiting = true;
console.debug(`Trying to get key ${node.cnodes}`);
uri = encodeURI(node.cnodes);
$http.get(`${window.viewPrefix}${$scope.currentCfg.cfgNum}/${uri}`).then(function (response) {
var a, data, l, len;
data = response.data;
// Manage datas errors
if (!data) {
d.reject('Empty response from server');
} else if (data.error) {
if (data.error.match(/setDefault$/)) {
if (node['default']) {
node.nodes = node['default'].slice(0);
} else {
node.nodes = [];
}
delete node.cnodes;
d.resolve('Set data to default value');
} else {
d.reject(`Server return an error: ${data.error}`);
}
} else {
// Store datas
delete node.cnodes;
if (!node.type) {
node.type = 'keyTextContainer';
}
node.nodes = [];
// TODO: try/catch
for (l = 0, len = data.length; l < len; l++) {
a = data[l];
if (a.template) {
a._nodes = templates(a.template, a.title);
}
node.nodes.push(a);
}
d.resolve('OK');
}
return $scope.waiting = false;
}, function (response) {
readError(response);
return d.reject('');
});
return d.promise;
};
$scope.openCnode = function (scope) {
return $scope.download(scope).then(function () {
return scope.toggle();
});
};
$scope.copyPath = function () {
var text = $scope.breadCrumb.join(" » ");
navigator.clipboard.writeText(text).then(function () {
$scope.$apply(function () {
$scope.copySuccess = true;
$timeout(function () {
$scope.copySuccess = false;
}, 400);
});
});
};
setHelp = function (scope) {
while (!scope.$modelValue.help && scope.$parentNodeScope) {
scope = scope.$parentNodeScope;
}
return $scope.helpUrl = scope.$modelValue.help || 'start.html#configuration';
};
// Form management
// `currentNode` contains the last select node
// method `diplayForm()`:
// - set the `form` property to the name of the form to download
// (`text` by default or `home` for node without `type` property)
// - launch getKeys to set `node.data`
// - hide tree when in XS size
$scope.getTrPath = function (scope) {
var path = [];
var trpath = [];
var current = scope;
var safetycount = 0;
while (current && current.$modelValue && safetycount < 100) {
safetycount = safetycount + 1;
if (current.$modelValue.title && current.$modelValue.title != path[0]) {
trpath.unshift(scope.translate(current.$modelValue.title));
path.unshift(current.$modelValue.title);
}
current = current.$parent;
}
return trpath;
};
$scope.displayForm = function (scope) {
var f, l, len, n, node, ref;
node = scope.$modelValue;
if (node.cnodes) {
$scope.download(scope);
}
if (node._nodes) {
$scope.stoggle(scope);
}
$scope.currentNode = node;
$scope.currentScope = scope;
f = node.type ? node.type : 'text';
if (node.nodes || node._nodes || node.cnodes) {
$scope.form = f !== 'text' ? f : 'mini';
} else {
$scope.form = f;
// Get datas
$scope.getKey(node);
}
if (node.type && node.type === 'simpleInputContainer') {
ref = node.nodes;
( run in 1.535 second using v1.01-cache-2.11-cpan-84e82930d8c )