Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
sapk committed Jul 11, 2016
1 parent d03a336 commit 8fae867
Show file tree
Hide file tree
Showing 16 changed files with 222 additions and 224 deletions.
13 changes: 6 additions & 7 deletions www/assets/js/init.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* global requirejs */
'use strict';
"use strict";
/*
* Init the app dependency with requirejs
*/
Expand Down Expand Up @@ -37,7 +37,7 @@ requirejs.config({
},
pouchdb: {
exports: 'PouchDB'
},
},
"pouchdb-authentication": ['pouchdb'],
vue: {
exports: 'Vue'
Expand All @@ -46,9 +46,6 @@ requirejs.config({
exports: 'VueRouter',
deps:['vue']
},
pouchdb: {
exports: 'PouchDB'
},
moment: {
exports: 'moment'
},
Expand All @@ -64,12 +61,14 @@ requirejs.config({
//Set the config for the i18n
//module ID
i18n: {
locale: language
locale: localStorage["sofia-language"] || navigator.language || navigator.userLanguage || 'en',
}
}
});


window.S = {}; //TODO remove this hack

requirejs(['cordova'], function(cordova){
// Load the main app module to start the app (in cordova)
requirejs(["main"]);
Expand All @@ -81,7 +80,7 @@ requirejs(['cordova'], function(cordova){
window.cordova = {
is_mock: true,
platformId : "browser"
}
};
// Load the main app module to start the app (in web version)
requirejs(["main"]);
} else {
Expand Down
33 changes: 20 additions & 13 deletions www/assets/js/main.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
define(['jquery','i18n!app/nls/base', 'vue', 'vue-router', 'moment', 'moment-locales','app/sofia.tool','app/sofia.config','app/sofia.user','app/sofia.db', 'app/sofia.data','platform/' + cordova.platformId + '/init','app/sofia.app','app/sofia.polyfill',], function ($,lang, Vue, VueRouter, moment,tool,config,user,db,data,platform,app) {
//Define primary object
var S = {
lang : lang
language : localStorage["sofia-language"] || navigator.language || navigator.userLanguage || 'en',
"use strict";
define(['jquery','i18n!app/nls/base', 'vue', 'vue-router', 'moment',
'app/sofia.tool','app/sofia.config','app/sofia.user','app/sofia.db', 'app/sofia.data',
'platform/' + cordova.platformId + '/init','app/sofia.vue','app/sofia.app','app/sofia.polyfill','moment-locales'],
function ($,lang, Vue, VueRouter, moment,
tool,config,user,db,data,platform,vue,app) {
//Define primary object
S = {
lang : lang,
language : localStorage["sofia-language"] || navigator.language || navigator.userLanguage || 'en', //TODO use language allready pass to requirejs

config : config,
tool:tool,
template:platform.template,
user:user,
db:db,
data: data, //TODO rename data to page or at least expose or regroup in data
platform:platform
platform:platform,
template:platform.template,
vue:vue,
app:app
};

console.log(S,'platform/' + cordova.platformId + '/init');

// Setup plugins
Vue.use(VueRouter);
moment.locale(S.language);

//Setup DB
db.setUrl(config.db); //TODO check usefullnes of that

//window.S = S; //TODO check if usefull

window.setTimeout(S.app.initialize,250); // Add time if all not already loaded for safety //TODO everythings is now ready

//Apply theming
Expand All @@ -30,9 +37,9 @@

return S;
//TODO HERE

/*
requirejs(['app/sofia.vue', ], function () {
requirejs([, ], function () {
window.setTimeout(S.app.initialize,250); // Add time if all not already loaded for safety
});
*/
Expand Down
7 changes: 4 additions & 3 deletions www/assets/js/page/add.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* global S */

define({
define(['i18n!app/nls/base'],function(lang) {
return {
options: {
title: S.lang["add"].capitalize(),
title: lang["add"].capitalize(),
displayQuickAddButton : false,
displaySearchbox: false
},
Expand Down Expand Up @@ -62,4 +62,5 @@ define({
});
}
}
};
});
42 changes: 22 additions & 20 deletions www/assets/js/page/home.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
/* global S */
define({
options : {
displaySearchbox: true,
displayQuickAddButton : true,
title: S.lang["my-sheets"].capitalize(),
titleInSearch: S.lang["search"].capitalize()
},
route: {
define(['i18n!app/nls/base'],function(lang) {
return {
options : {
displaySearchbox: true,
displayQuickAddButton : true,
title: lang["my-sheets"].capitalize(),
titleInSearch: lang["search"].capitalize()
},
route: {
data: function () {
if(S.user._current.isAdmin()) {
S.vue.router.app.$children[0].$data.options.title = S.lang["overview-of-sheets"].capitalize();
}
return S.db.fiches.getAllWithMine()
}
},
data: function () {
if(S.user._current.isAdmin()) {
S.vue.router.app.$children[0].$data.options.title = S.lang["overview-of-sheets"].capitalize();
}
return S.db.fiches.getAllWithMine()
return {
fiches: [],
my_fiches: []
};
}
},
data: function () {
return {
fiches: [],
my_fiches: []
};
}
})
};
});
7 changes: 5 additions & 2 deletions www/assets/js/page/memo.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* global S */
define({

define(['i18n!app/nls/base'],function(lang) {
return {
options : {
title: S.lang["memo"].capitalize(),
title: lang["memo"].capitalize(),
displayQuickAddButton : false,
displaySearchbox: false
},
Expand All @@ -10,4 +12,5 @@ define({
return S.db.config.getMemo()
}
},
}
})
89 changes: 46 additions & 43 deletions www/assets/js/page/settings.js
Original file line number Diff line number Diff line change
@@ -1,50 +1,53 @@
/* global S */
define({
options : {
title: S.lang["settings"].capitalize(),

define(['i18n!app/nls/base'],function(lang) {
return {
options : {
title: lang["settings"].capitalize(),
displayQuickAddButton : false,
displaySearchbox: false
},
route: {
data: function () {
var ret = {
user : S.user._current,
lang : S.lang,
askFor : []
}
$.each(S.config.local["ask-for"],function(id,value){
ret.askFor.push({"id":id,"value":value,"lang":S.lang.config[id] || id});
});
return ret;
}
},
methods: {
update: function (event) {
console.log(this,event,$(event.srcElement).attr("name"),$(event.srcElement).is(':checked'))
S.config.local["ask-for"][$(event.srcElement).attr("name")] = $(event.srcElement).is(':checked');
localStorage["sofia-local-config"] = JSON.stringify(S.config.local)
},
resetCredConfig: function(){
S.user.reset();
window.location.reload();
},
resetServerConfig: function(){
delete localStorage['sofia-server-config'];
window.location.reload();
route: {
data: function () {
var ret = {
user : S.user._current,
lang : lang,
askFor : []
}
$.each(S.config.local["ask-for"],function(id,value){
ret.askFor.push({"id":id,"value":value,"lang":lang.config[id] || id});
});
return ret;
}
},
showLangModal : function() {
S.tool.getDialog("#choose-lang-dialog").showModal();
},
changeLanguage: function (event) {
localStorage["sofia-language"] = $.trim($(event.srcElement).attr("data-id"));
S.tool.getDialog("#choose-lang-dialog").close();
window.location.reload(); //Reload app
methods: {
update: function (event) {
console.log(this,event,$(event.srcElement).attr("name"),$(event.srcElement).is(':checked'))
S.config.local["ask-for"][$(event.srcElement).attr("name")] = $(event.srcElement).is(':checked');
localStorage["sofia-local-config"] = JSON.stringify(S.config.local)
},
resetCredConfig: function(){
S.user.reset();
window.location.reload();
},
resetServerConfig: function(){
delete localStorage['sofia-server-config'];
window.location.reload();
},
showLangModal : function() {
S.tool.getDialog("#choose-lang-dialog").showModal();
},
changeLanguage: function (event) {
localStorage["sofia-language"] = $.trim($(event.srcElement).attr("data-id"));
S.tool.getDialog("#choose-lang-dialog").close();
window.location.reload(); //Reload app
},
clearLocalDB: function(){
S.db.clearLocal().then(function(){window.location.reload();}).catch(function (err) {
console.log(err);
window.location.reload(); //We also reload in case
});
}
},
clearLocalDB: function(){
S.db.clearLocal().then(function(){window.location.reload();}).catch(function (err) {
console.log(err);
window.location.reload(); //We also reload in case
});
}
},
};
});
7 changes: 3 additions & 4 deletions www/assets/js/sofia.app.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

'use strict';
define([], function() {
var app = {
// Application Constructor
initialize: function () {
S.app.bindEvents();
app.bindEvents();
},
// Bind Event Listeners
//
Expand All @@ -13,7 +12,7 @@ define([], function() {
bindEvents: function () {
//We use requirejs so everything is ready whenwe are here
//document.addEventListener('deviceready', this.onDeviceReady, false);
window.setTimeout(S.app.onDeviceReady, 1000); //TODO when everything is rework test to remove this timing
window.setTimeout(app.onDeviceReady, 1000); //TODO when everything is rework test to remove this timing
},
removeLoader: function () {
$('body>.app-loading').remove();
Expand All @@ -25,7 +24,7 @@ define([], function() {
S.platform.events.afterDeviceReady();
}
$("body").removeClass("loading");
window.setTimeout(S.app.removeLoader, 1000);
window.setTimeout(app.removeLoader, 1000);
}
};
return app;
Expand Down
6 changes: 3 additions & 3 deletions www/assets/js/sofia.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
define([], function() {
define(["jquery"], function($) {
var config = {
user : {
username : "",
Expand Down Expand Up @@ -55,11 +55,11 @@ define([], function() {
}
}
};

$.extend(true, config.user, (typeof localStorage["sofia-user-config"] === "string") ? JSON.parse(localStorage["sofia-user-config"]) : null);
$.extend(true, config.db, (typeof localStorage["sofia-server-config"] === "string") ? JSON.parse(localStorage["sofia-server-config"]) : null);
$.extend(true, config.local, (typeof localStorage["sofia-local-config"] === "string") ? JSON.parse(localStorage["sofia-local-config"]) : null);
//TODO check if all config is ok

return config;
});
2 changes: 1 addition & 1 deletion www/assets/js/sofia.data.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
'use strict';
"use strict";
define(['app/page/home','app/page/login','app/page/fiche','app/page/add','app/page/memo','app/page/settings'], function (pHome,pLogin,pFiche,pAdd,pMemo,pSettings) {
var data = {
pages: {
Expand Down
Loading

0 comments on commit 8fae867

Please sign in to comment.