diff --git a/Makefile b/Makefile index 3933860b5..9e84762d0 100644 --- a/Makefile +++ b/Makefile @@ -190,6 +190,10 @@ JSSRCFILES:=$(shell find $(SRCMANAGERDIR)/site/static/js $(SRCPORTALDIR)/example $(SRCMANAGERDIR)/site/static/bwr/file-saver.js/FileSaver.js CSSSRCFILES:=$(shell find $(SRCMANAGERDIR)/site/static/css $(SRCPORTALDIR)/example -type f -name '*.css' ! -name '*.min.css') +# Coffee files +COFFEESRCFILES:=$(shell find $(SRCMANAGERDIR)/site/coffee/ -type f) +COFFEEDSTFILES:=$(subst coffee/,static/js/,$(COFFEESRCFILES:.coffee=.js)) + # Minified files JSDSTFILES=$(JSSRCFILES:.js=.min.js) CSSDSTFILES=$(CSSSRCFILES:.css=.min.css) @@ -258,6 +262,12 @@ configure: json common_conf handler_conf portal_conf manager_conf minify: $(JSDSTFILES) $(CSSDSTFILES) +$(SRCMANAGERDIR)/site/static/js/%.js: $(SRCMANAGERDIR)/site/coffee/%.coffee + @if which coffee >/dev/null; then \ + echo "Compiling $(SRCMANAGERDIR)/site/coffee/$*.coffee"; \ + coffee -c -o $(SRCMANAGERDIR)/site/static/js/ $(SRCMANAGERDIR)/site/coffee/$*.coffee; \ + fi + %.min.css: %.css @echo "Compressing $*.css" @yui-compressor $*.css > $*.min.css @@ -272,7 +282,7 @@ fastcgi-server/man/llng-fastcgi-server.1p: fastcgi-server/sbin/llng-fastcgi-serv # Perl libraries configuration json: $(MANAGERJSONDST) fastcgi-server/man/llng-fastcgi-server.1p - @if which yui-compressor; then $(MAKE) minify; fi + @if which yui-compressor >/dev/null; then $(MAKE) minify; fi $(MANAGERJSONDST): $(MANAGERJSONSRC) ./scripts/jsongenerator.pl @@ -1010,7 +1020,7 @@ tidy: clean $(MAKE) json tidy-js: clean - @find $(SRCMANAGERDIR)/site/static/js/ e2e-tests/ $(SRCPORTALDIR)/example \ + @find e2e-tests/ $(SRCPORTALDIR)/example \ -type f \ -name '*.js' \ ! -name 'jq*' \ diff --git a/lemonldap-ng-manager/site/coffee/llApp.coffee b/lemonldap-ng-manager/site/coffee/llApp.coffee new file mode 100644 index 000000000..8f9c5b465 --- /dev/null +++ b/lemonldap-ng-manager/site/coffee/llApp.coffee @@ -0,0 +1,237 @@ +### +LemonLDAP::NG base app module + + This file contains: + - 3 AngularJS directives (HTML attributes): + * `on-read-file` to get file content + * `resizer` to resize HTML div + * `trspan` to set translated message in HTML content + - a AngularJS factory to handle 401 Ajax responses +### + +llapp = angular.module 'llApp', [] + +# TRANSLATION SYSTEM +# +# It provides: +# - 3 functions to translate: +# * translate(word) +# * translateP(paragraph): only __words__ are translated +# * translateField(object, property) +# - an HTML attribute called 'trspan'. Exemple:

+ +# $translator provider + +llapp.provider '$translator', -> + res = {} + # Language detection + if navigator + langs = [] + langs2 = [] + nlangs = [ navigator.language ] + if navigator.languages + nlangs = navigator.languages + for nl in nlangs + for al in window.availableLanguages + if al == nl + langs.push al + else if al.substring(0, 1) == nl.substring(0, 1) + langs2.push al + res.lang = if langs[0] then langs[0] else if langs2[0] then langs2[0] else 'en'; + else + res.lang = 'en' + + # Internal properties + res.deferredTr = [] + res.translationFields = {} + + # Translation methods + # 1. word translation + res.translate = (s) -> + if res.translationFields[s] + s = res.translationFields[s] + return s + + # 2. node field translation + res.translateField = (node, field) -> + res.translate node[field] + + # 3. paragraph translation (verify that json is available + res.translateP = (s) -> + if s and res.translationFields.portal + s = s.replace /__(\w+)__/g, (match,w) -> + res.translate w + s + + # Initialization + this.$get = [ '$q', '$http', ($q, $http) -> + res.last = '' + res.init = (lang) -> + lang = res.lang unless lang + d = $q.defer() + if res.last != lang + res.last = lang + $http.get("#{window.staticPrefix}languages/#{lang}.json").then (response) -> + res.translationFields = response.data + for h in res.deferredTr + h.e[h.f] res.translationFields[h.m] + res.deferredTr = [] + d.resolve "Translation files loaded" + , (response) -> + d.reject '' + else + d.resolve "No change" + d.promise + res + ] + this + +# Translation directive (HTML trspan tag) +llapp.directive 'trspan', [ '$translator', ($translator) -> + restrict: 'A' + replace: false + transclude: true + scope: + trspan: "@" + link: (scope, elem, attr) -> + if $translator.translationFields.portal + attr.trspan = $translator.translate(attr.trspan) + # Deferred translations will be done after JSON download + else + $translator.deferredTr.push + e: elem + f: 'text' + m: attr.trspan + elem.text attr.trspan + template: '' +] + +# Form menu management +# +# Two parts: +# - $htmlParams: used to store values inserted as