...
 
Commits (2)
This diff is collapsed.
views = require('./views.js');
module.exports = {
getRoutes: function () {
var arr = [
['get', '#/', views.others.home],
['get', '#/welcome', views.others.welcome],
['get', '#/our-promise', views.others.ourpromise],
['get', '#/terms', views.others.terms],
['get', '#/register', views.register.getregister],
['post', '#/register', views.register.postregister],
['get', '#/login', views.auth.getlogin],
['post', '#/login', views.auth.postlogin],
['get', '#/logout', views.auth.getlogout],
['get', '#/request/:id', views.request.getarequest],
['get', '#/returnrequest/:id/:payload', views.request.getreturnrequest],
['get', '#/completerequest/:id', views.request.getacompleterequest],
['get', '#/request_done/:id', views.request.getrequestdone],
['get', '#/connect/:token/:settingsuri/:scope', views.connect.getconnect],
['get', '#/shares', views.request.getshares]
];
return arr;
},
}
\ No newline at end of file
module.exports = {
ourpromise : function(e){
e.partial('views/promise.tpl', function(t){
tools.setTheme('grey');
tools.setLayout('wizard');
});
}
};
\ No newline at end of file
register: require('./views/register.js'),
auth: require('./views/auth.js'), //login logout etc
connect: require('./views/connect.js'),
request: require('./views/request.js'),
others: require('./views/others.js'), // home, our-promise, welcome, terms
}
\ No newline at end of file
global.entity = require('../entity.js');
global.tools = require('../tools.js')
module.exports = {
login : function(e) {
console.log('nu in login view functie');
this.title('Inloggen');
tools.setTheme('pink');
tools.setLayout('wizard');
e.partial('views/login.tpl', null, function(t){
var pinInstance = $('#pinwrapper').pinlogin({
placeholder : '*',
complete : function(pin){
$('#pin').val(pin);
$('#loginForm').submit();
}
});
});
},
postlogin : function(e){
entity.login(e.params['pin'], function(result){
if (result){
onAppLoad(e); // trigger app loaded event manually
e.redirect('#/');
}
else {
// todo, make nice flash message
alert ('Ongeldige pincode, probeer het opnieuw');
}
});
},
logout : function(e) {
// logout user
entity.logout(function(){
// run unload tasks
onAppUnload(e);
// redirect back
e.redirect('#/');
});
}
}
\ No newline at end of file
global.tools = require('../tools.js')
global.provider = require('../provider.js');
module.exports = {
getconnect: function (e) {
// handle, initialize and redirect 3rd party connection requests
context.init(function () {
$.getJSON(e.params['settingsuri'], async function (result) {
// generate unique hash (will be used as token and identifier for this request)
var key = tools.uuidv4();
// save it in db
context.setItem('requests', key, { token: e.params['token'], name: result.name, settingsuri: e.params['settingsuri'], scope: e.params['scope'] });
//context.storeConnectionRequest(result.appname, data['token'], result.name, data['settingsuri']);
// get update api url from config.json. to do so, first load the json
await provider.init(e.params['settingsuri']);
var stateUrl = provider.settings.endpoints.state;
stateUrl = stateUrl.replace('[token]', encodeURIComponent(e.params['token']));
stateUrl = stateUrl.replace('[state]', encodeURIComponent('connecting'));
// update client api to 'connecting'
app.trigger('connection-update-clientapi', { token: e.params['token'], apiuri: stateUrl });
// redirect 'home' -> and automatic go to registration or login when needed
e.redirect('#/');
});
});
},
}
\ No newline at end of file
global.tools = require('../tools.js')
module.exports = {
home: function (e) {
//e.use('Template','tpl');
e.partial('views/home.tpl', null, function (t) {
tools.setTheme('grey');
tools.setLayout('app');
async function runasync() {
// get the first request found (if there is one)
// todo: what if user cancels the request and want to go to the home screen?
// possible solution: do this check directly after login and if there's no request, go to #/
let request = await provider.getRequest();
tools.log(request);
}
runasync();
// do other sync things here..?
// like showing available data in vault / pending requests
});
},
terms: function (e) {
e.partial('views/terms.tpl', function (t) {
tools.setTheme('white');
tools.setLayout('wizard');
});
},
welcome: function (e) {
e.partial('views/welcome.tpl', null, function (a) {
tools.setTheme('');
tools.setLayout('wizard');
const _C = document.querySelector('.panelcontainer'),
N = _C.children.length;
let i = 0, x0 = null, locked = false, w, last = -1;
function unify(e) { return e.changedTouches ? e.changedTouches[0] : e };
function lock(e) {
x0 = unify(e).clientX;
_C.classList.toggle('smooth', !(locked = true))
};
function drag(e) {
//e.preventDefault();
if (locked)
_C.style.setProperty('--tx', `${Math.round(unify(e).clientX - x0)}px`)
};
function move(e) {
if (locked) {
let dx = unify(e).clientX - x0, s = Math.sign(dx),
f = +(s * dx / w).toFixed(2);
if ((i > 0 || s < 0) && (i < N - 1 || s > 0) && f > .2) {
_C.style.setProperty('--i', i -= s);
f = 1 - f
}
tools.log(i);
activate(i);
_C.style.setProperty('--tx', '0px');
_C.style.setProperty('--f', f);
_C.classList.toggle('smooth', !(locked = false));
x0 = null
}
};
function size() { w = window.innerWidth };
size();
_C.style.setProperty('--n', N);
addEventListener('resize', size, false);
_C.addEventListener('mousedown', lock, false);
_C.addEventListener('touchstart', lock, { passive: true });
_C.addEventListener('mousemove', drag, false);
_C.addEventListener('touchmove', drag, { passive: true });
_C.addEventListener('mouseup', move, false);
_C.addEventListener('touchend', move, false);
//document.getElementById('prev').addEventListener('click', prev, false);
//document.getElementById('next').addEventListener('click', next, false);
activate(0);
function activate(bulletnr) {
$('#progress' + bulletnr).toggleClass('on');
if (last != -1)
$('#progress' + last).toggleClass('on');
last = bulletnr;
}
function next() {
i++;
f = 0;
//_C.classList.toggle('smooth', !(locked = false));
_C.style.setProperty('--i', i);
_C.style.setProperty('--f', 0);
_C.style.setProperty('--tx', '0px');
}
function prev() {
i--;
f = 0;
//_C.classList.toggle('smooth', !(locked = false));
_C.style.setProperty('--i', i);
_C.style.setProperty('--f', 0);
_C.style.setProperty('--tx', '0px');
}
});
},
ourpromise: function (e) {
e.partial('views/promise.tpl', function (t) {
tools.setTheme('grey');
tools.setLayout('wizard');
});
}
}
\ No newline at end of file
global.tools = require('../tools.js')
module.exports = {
getregister: function (e) {
e.partial('views/register.tpl', null, function (t) {
tools.setTheme('pink');
tools.setLayout('wizard');
var pincode = '';
var pinInstance = $('#pinwrapper').pinlogin({
placeholder: '*',
reset: false,
complete: function (pin) {
pincode = pin;
// focus repeat instance
pinrepeatInstance.focus(0);
// disable this instance
pinInstance.disable();
}
});
var pinrepeatInstance = $('#pinrepeatwrapper').pinlogin({
placeholder: '*',
reset: false,
autofocus: false,
complete: function (pin) {
if (pincode != pin) {
pincode = '';
// reset both instances
pinInstance.reset();
pinrepeatInstance.reset();
// disable repeat instance
pinrepeatInstance.disable();
alert('Pincode komt niet overeen, probeer het opnieuw');
}
else {
// set pincode in hidden input
$('#pin').val(pin);
// disable both instances
pinInstance.disable();
pinrepeatInstance.disable();
$('#registerSubmit')
.attr('disabled', false)
.click(function () {
$('#registerForm').submit();
});
}
}
});
// disable repeat instance at start
//( Commented this part due to issues in Browser. Need to recheck)
pinrepeatInstance.disable();
});
},
postregister: function (e) {
e.partial('views/register-wait.tpl', null, function (t) {
tools.setTheme('');
tools.setLayout('wizard');
/// begin
const _C = document.querySelector('.panelcontainer'),
N = _C.children.length;
let i = 0, x0 = null, locked = false, w, last = -1;
function unify(e) { return e.changedTouches ? e.changedTouches[0] : e };
function lock(e) {
x0 = unify(e).clientX;
_C.classList.toggle('smooth', !(locked = true))
};
function drag(e) {
//e.preventDefault();
if (locked)
_C.style.setProperty('--tx', `${Math.round(unify(e).clientX - x0)}px`)
};
function move(e) {
if (locked) {
let dx = unify(e).clientX - x0, s = Math.sign(dx),
f = +(s * dx / w).toFixed(2);
if ((i > 0 || s < 0) && (i < N - 1 || s > 0) && f > .2) {
_C.style.setProperty('--i', i -= s);
f = 1 - f
}
tools.log(i);
activate(i);
_C.style.setProperty('--tx', '0px');
_C.style.setProperty('--f', f);
_C.classList.toggle('smooth', !(locked = false));
x0 = null
}
};
function size() { w = window.innerWidth };
size();
_C.style.setProperty('--n', N);
addEventListener('resize', size, false);
_C.addEventListener('mousedown', lock, false);
_C.addEventListener('touchstart', lock, { passive: true });
_C.addEventListener('mousemove', drag, false);
_C.addEventListener('touchmove', drag, { passive: true });
_C.addEventListener('mouseup', move, false);
_C.addEventListener('touchend', move, false);
//document.getElementById('prev').addEventListener('click', prev, false);
//document.getElementById('next').addEventListener('click', next, false);
activate(0);
function activate(bulletnr) {
$('#progress' + bulletnr).toggleClass('on');
if (last != -1)
$('#progress' + last).toggleClass('on');
last = bulletnr;
}
/// end template javascript code
// register registration worker
var worker = new Worker('../assets/js/worker.js');
worker.onmessage = function (result) {
if (result.data.action == 'register' && result.data.type == 'finished') {
// create a session right away
entity.created = true;
// vault created, show overlay
$('#doneOverlay').addClass('show');
// Redirect to login (no more autologin, this is to force the user to enter the pincode again = better remembering)
window.setTimeout(function () {
e.redirect('#/');
}, 3000);
}
};
// start async registration process
worker.postMessage({ action: 'register', params: e.params['pin'] });
});
},
}
\ No newline at end of file
global.tools = require('../tools.js')
global.provider = require('../provider.js');
global.context = require('../context.js');
module.exports = {
getarequest: function (e) {
// view a request
async function runasync() {
provider.request = await context.getItem('requests', e.params['id']);
await provider.init(provider.request.settingsuri);
let scope = await provider.getScope(provider.request.scope);
// generate the right redirect to third party url (the one that offers the data)
scope.settings.endpoints.connect = scope.settings.endpoints.connect.replace('[settingsurl]', encodeURIComponent(provider.request.settingsuri));
scope.settings.endpoints.connect = scope.settings.endpoints.connect.replace('[scope]', encodeURIComponent(scope.scope));
scope.settings.endpoints.connect = scope.settings.endpoints.connect.replace('[token]', encodeURIComponent(e.params['id'])); // todo: make unique token for use only between schluss.app and third party (duo)
// returnurl:
var returnurl = window.location.origin + '#/returnrequest/' + e.params['id'];
scope.settings.endpoints.connect = scope.settings.endpoints.connect.replace('[returnurl]', encodeURIComponent(returnurl));
tools.log('scope:');
tools.log(scope);
await e.partial('views/request.tpl', { provider: provider.settings, scope: scope, id: e.params['id'] }, function (t) {
tools.setTheme('grey');
tools.setLayout('wizard');
// for now: 1 single source only possible, future must be able to contain multiple
// when is filled
if (provider.request.payload) {
//$('#payload').html(provider.request.payload);
//$('#payload').show();
$('#getContentBtn')
.html('<img src="/assets/img/check-green.png" /> In kluis')
.attr('href', '#')
.addClass('inlinebutton green')
.show();
$('#checkboxOff').hide();
$('#checkboxOn').show();
$('#processBtn').removeAttr('disabled');
$('#longpressMsg').show();
// Logic for longpress button - future: remove from app.js
// in this case, already removed jquery dependencies
let btn = document.getElementById('processBtn');
let timer, start, end, pressTime = 3000;
// when mousedown / touchstart
btn.onPress = function () {
start = new Date();
btn.classList.add('pressing');
// add x sec pressing time timer
timer = setTimeout(function () {
// cleanup and reset
btn.classList.remove('pressing');
btn.classList.add('pressed');
btn.disabled = true; // disable the button
// call onPressed handler, if available
if (btn.onPressed)
btn.onPressed();
}, pressTime);
}
// when mouseup / touchend
btn.onPressCancel = function () {
end = new Date();
btn.classList.remove('pressing');
clearTimeout(timer);
// when button is released to quick, shake it (with a max of 1 sec after pressing)
if (end - start <= 1000) {
btn.classList.add('shake');
setTimeout(function () {
btn.classList.remove('shake');
}, 820);
}
}
// attach event listeners
// mouse
btn.addEventListener('mousedown', btn.onPress);
btn.addEventListener('mouseup', btn.onPressCancel);
// touch
btn.addEventListener("touchstart", btn.onPress, { passive: true });
btn.addEventListener("touchend", btn.onPressCancel);
// handler for what to do when user pressed the button for x time
btn.onPressed = function () {
// submit the form
//document.getElementById('processForm').submit();
e.redirect('#/completerequest/' + e.params['id']);
}
// End logic for longpress button
}
// when not filled
else {
//$('#payload').hide();
$('#getContentBtn')
.attr('href', '#')
.addClass('inlinebutton pink')
.html('Ophalen')
.click(function () {
// show overlay that user s beeing redirect externally
$('#redirectOverlay').addClass('show');
$('#redirecturlname').text(tools.shorten(scope.settings.endpoints.connect, 30));
window.setTimeout(function () {
window.location.href = scope.settings.endpoints.connect;
}, 2000);
})
$('#checkboxOff').show();
$('#checkboxOn').hide();
$('#processBtn').attr('disabled', 'disabled');
$('#longpressMsg').hide();
}
// when via
//if ()
$('#requestVia').html('<img src="/assets/img/right-arrow.png" /> <span class="pink">via: </span>' + scope.settings.name);
tools.log(provider.request.payload);
});
}
runasync();
},
getreturnrequest: function (e) {
//this.post('#/returnrequest/:id', function(e){ // payload is posted!
// post not working yet because of Content Security Policy! - so it is a get request for now
tools.log('id:' + e.params['id']);
tools.log('payload:' + e.params['payload']);
async function runasync() {
let item = await context.getItem('requests', e.params['id']);
item.payload = decodeURIComponent(e.params['payload']);
await context.setItem('requests', e.params['id'], item);
e.redirect('#/request/' + e.params['id']);
}
runasync();
},
getacompleterequest: function (e) {
// The request is being completed, now time to send the payload to provider and update state
e.partial('views/request_processing.tpl', null, function (t) {
tools.setTheme('grey');
tools.setLayout('wizard');
async function runasync() {
// update state
var stateUrl = provider.settings.endpoints.state;
stateUrl = stateUrl.replace('[token]', encodeURIComponent(provider.request.token));
stateUrl = stateUrl.replace('[state]', encodeURIComponent('connected'));
$.get(stateUrl);
// send payload
var url = provider.settings.endpoints.return;
url = url.replace('[token]', encodeURIComponent(provider.request.token));
url = url.replace('[payload]', encodeURIComponent(provider.request.payload));
// post data to provider
$.post(url, { token: provider.request.token, payload: encodeURIComponent(provider.request.payload) }, function (data) {
//$.get(url, function(data){
tools.log('request shared');
// show overlay that it's done
window.setTimeout(function () {
// completed, show overlay
$('#doneOverlay').addClass('show');
// redirect
window.setTimeout(function () {
e.redirect('#/request_done/' + e.params['id']);
}, 3000);
}, 3000);
});
}
runasync();
});
},
getrequestdone: function (e) {
// delete open request
//context.removeItem('requests', e.params['id']);
e.title('Dataverzoek afgerond');
e.partial('views/request_done.tpl', null, function () {
tools.setTheme('grey');
tools.setLayout('app');
async function runasync() {
let item = await context.getItem('requests', e.params['id']);
$('#companyname').text(tools.uppercaseFirstChar(item.name));
// delete open request to wrap things up
context.removeItem('requests', e.params['id']);
}
runasync();
});
},
getshares: function (e) {
// show all shares (processed requests / contracts)
e.partial('views/shares.tpl', null, function () {
tools.setTheme('grey');
tools.setLayout('wizard');
});
}
}
\ No newline at end of file