Ejemplo n.º 1
0
		.done(function (success) {

			if(success.length === 0)
			{
				//the file didnt exist create it if translator
				if(isTranslator)
				{
					if(lang != "en")
					{//make a copy of en and create the new one
						return deep("translate::?language=" + smart.country + "-en" +  "&module=" + moduleName)
						//.log("------Getting Default EN translations for creating " + lang)
						.done(function (success) {
							if(success.length === 0)
								return deep.errors.NotFound(); // the module didnt exist yet
							else
							{
								success = success.shift();
								deep.store("translate").post({
									language:smart.country + "-" + lang,
									module:moduleName,
									translations:success.translations
								}).done(function (success) {
									//console.log("creating default SUCCESS");
									var rez = null;
									if(path === "")
										rez = success.translations;
									else
										rez = deep.query(success.translations,  path);
									res.writeHead(200, {'Content-Type': 'application/json;charset=utf-8', "Location":req.url});
									res.end(JSON.stringify(rez));
								}).fail(function (e) {
									console.log("creating default ERROR");
									res.writeHead(e.status || 400, {'Content-Type': 'text/html'});
									res.end("error when creating the default translation file : "+JSON.stringify(e));
								});
							}
							
						});
					}
				}
				else
				{
					return deep.errors.NotFound();
				}
			}
			else
			{
				success = success.shift();
				//console.log("Path for translation : ", path);
				var rez = null;
				if(path === "")
					rez = success.translations;
				else
					rez = deep.query(success.translations,  path);
				// console.log("results for translation : ", rez);
				res.writeHead(200, {'Content-Type': 'application/json;charset=utf-8', "Location":req.url});
				res.end(JSON.stringify(rez));
			}
		}).fail(function (e) {
Ejemplo n.º 2
0
		loggedIn:deep.compose.before(function(passport, from)
		{
            var user = passport.user;
            this.currentUser = user;
            this.passport = passport;
            // console.log("logged in : ", user, " - from : ", from, " - : pass : "******"passport", passport);
            deep.generalMode(passport.roles);
	
			var self = this;
            return deep(this)
            .query("/userDatas")
            .deepLoad(user)
            .done(function(){
                if(smart.userDatas.profile)
                    self.userDatas.profile = self.userDatas.profile.shift();
                return smart.init(from);
            })
            .fail(function (e) {
                deep.generalMode("public");
                smart.gui().error(e).loading(false).login();
            });
		})
Ejemplo n.º 3
0
		init:deep.compose.createIfNecessary().after(function () {
			return deep(this).query("./subs/*").bottom(deep.ui.ViewController).run("init");
		})
Ejemplo n.º 4
0
	return function (req, res, next)
	{
		//console.log("Translate middleware : req url = ", req.url);
		var lang = deep.context.language;
		lang = "nl";
		var splitted = req.url.split("/");
		splitted.shift(); //drop the first empty element
		//console.log("Translate middleware : splitted url = ", lang, splitted);

		if(splitted[0] != "translate")
			return next();
		
		splitted.shift();

		var roles = deep.context.modes.roles, isTranslator = false;
		if(roles && roles.foreach)
		{
			if(deep.utils.inArray("translator", roles))
				isTranslator = true;
		}
		else
		{
			if(roles == "translator")
				isTranslator = true;
		}
		isTranslator = true;

		var moduleName = splitted.shift();
		var path = splitted.join("/");

		switch(req.method.toLowerCase())
		{
			case "get":
				break;
			case "patch":
				var action = null;
				if(isTranslator)
					action = deep.store(store).get("?language=" + smart.country + "-" + lang + "&module=" + moduleName)
					.done(function(results){
						if(results.length === 0)
							return deep.errors.NotFound();
						var datas = results.shift();
						this.patch(req.body,{ id:"/"+datas.id+"/translations/"+path });
					});
				else
					action = deep.errors.Forbidden("you need to be translator to perform this operation.");
				deep.when(action)
				.done(function (success) {
					res.writeHead(200, {'Content-Type': 'application/json;charset=utf-8', "Location":req.url});
					res.end(JSON.stringify(success.translations));
				})
				.fail(function(e){
					console.log("translation error : ", e.toString());
					res.writeHead(e.status || 400, {'Content-Type': 'text/html'});
					res.end("error : "+JSON.stringify(e));
				});
				return;
			default: throw deep.errors.MethodNotAllowed();
		}

		var query = "translate::?language=" + smart.country + "-" + lang + "&module=" + moduleName;
		//console.log("Translation Query = ", query);
		deep(query)
		.done(function (success) {

			if(success.length === 0)
			{
				//the file didnt exist create it if translator
				if(isTranslator)
				{
					if(lang != "en")
					{//make a copy of en and create the new one
						return deep("translate::?language=" + smart.country + "-en" +  "&module=" + moduleName)
						//.log("------Getting Default EN translations for creating " + lang)
						.done(function (success) {
							if(success.length === 0)
								return deep.errors.NotFound(); // the module didnt exist yet
							else
							{
								success = success.shift();
								deep.store("translate").post({
									language:smart.country + "-" + lang,
									module:moduleName,
									translations:success.translations
								}).done(function (success) {
									//console.log("creating default SUCCESS");
									var rez = null;
									if(path === "")
										rez = success.translations;
									else
										rez = deep.query(success.translations,  path);
									res.writeHead(200, {'Content-Type': 'application/json;charset=utf-8', "Location":req.url});
									res.end(JSON.stringify(rez));
								}).fail(function (e) {
									console.log("creating default ERROR");
									res.writeHead(e.status || 400, {'Content-Type': 'text/html'});
									res.end("error when creating the default translation file : "+JSON.stringify(e));
								});
							}
							
						});
					}
				}
				else
				{
					return deep.errors.NotFound();
				}
			}
			else
			{
				success = success.shift();
				//console.log("Path for translation : ", path);
				var rez = null;
				if(path === "")
					rez = success.translations;
				else
					rez = deep.query(success.translations,  path);
				// console.log("results for translation : ", rez);
				res.writeHead(200, {'Content-Type': 'application/json;charset=utf-8', "Location":req.url});
				res.end(JSON.stringify(rez));
			}
		}).fail(function (e) {
			console.log("Fail to catch a translation");
			res.writeHead(e.status || 400, {'Content-Type': 'text/html'});
			res.end("error : "+JSON.stringify(e));
		});

		
	};
Ejemplo n.º 5
0
        init:function(initPath){
        	var self = this;
            // TODO : flatten ocm, load smart, try relog, + launch smart.app().load() + init() if relog fail (because public)
            console.log("smart.init() : ", initPath);
            var lang = this.language = $.jStorage.get("language");
            if(!lang) 
            {
            	// TODO : write script that do it for all language
            	lang = navigator.language || navigator.userLanguage;
		        if (lang.indexOf('en') > -1)
		          this.language = "en";
		        //else if (lang.indexOf('fr') > -1)
		        //  this.language = "fr";
		        else if (lang.indexOf('nl') > -1)
		          this.language = "nl";
		        else
		          this.language = "en";
			}
            $.jStorage.set("language", this.language);

            $.address.externalChange(function(event) {
                console.log(" $.address.externalChange : event : ", event);
                self.urlChanged(event);
            });
            $.address.internalChange(function (event) {
                console.log(" $.address.internalChange : event : ", event);
            });

            return deep.all([
                deep(this.externals).deepLoad(),
                this.views.flatten(),
                this.gui.flatten(),
                this.routes.flatten()
            ])
            .done(function(success){
                console.log("smart flattened")
                var passport = $.jStorage.get("passport");
                if(passport instanceof Array)
                {
                    $.jStorage.set("passport",null);
                    passport = null;
                }    
                if(passport && $.cookie("autobahn-session"))
                {
                    //console.log("try reload passport");
                    return deep.getAll(["user::"+passport.userId, "passport::"+passport.id])
                    .done(function(results){
                        var user = results.shift();
                        var passport = results.shift();
                        passport.user = user;
                        // console.log("passport from store : ", passport)
                        if(!passport)
                            return deep.errors.Internal();
                        smart.loggedIn(passport, initPath);
                    })
                    .fail(function (error) {
                        console.log("error while reloading passport : ", error);
                        deep.generalMode("public");
                        smart.app().init(initPath);
                    });
                }
                deep.generalMode("public");
                smart.app().init(initPath);
            })
        },