summaryrefslogtreecommitdiffstats
path: root/nfsw/static/nfsw.js
diff options
context:
space:
mode:
Diffstat (limited to 'nfsw/static/nfsw.js')
-rw-r--r--nfsw/static/nfsw.js87
1 files changed, 87 insertions, 0 deletions
diff --git a/nfsw/static/nfsw.js b/nfsw/static/nfsw.js
new file mode 100644
index 0000000..6ad5838
--- /dev/null
+++ b/nfsw/static/nfsw.js
@@ -0,0 +1,87 @@
+window.nfsw = {
+ fErr: function(msg) {
+ $('.msg-block .content p').empty().text(msg);
+ $('.msg-block .content').addClass('error');
+ $('.msg-block').show();
+ },
+ fInfo: function(msg) {
+ $('.msg-block .content p').empty().text(msg);
+ $('.msg-block .content').addClass('info');
+ $('.msg-block').show();
+ },
+ fFormInit: function() {
+ var root = this;
+
+ $('form.auth').submit(function(ev) {
+ ev.preventDefault();
+
+ root.fFormPost($(this).serialize());
+ });
+ },
+ fFormPost: function(post) {
+ var root = this;
+
+ $.post('/auth/start', post)
+ .done(function(data, status, xhr) {
+ if (!'status' in data) {
+ root.fErr('Unable to log you in!');
+ }
+ var status = data['status'];
+
+ if (status == 'pass') {
+ return root.fFormAskPass(data['msg']);
+ }
+ if (status == 'error') {
+ return root.fFormError(data);
+ }
+ if (status == 'ok') {
+ return root.fFormPostOk(data);
+ }
+
+ root.fErr('Unknow error. Unable to log you in!');
+ })
+ .fail(function(xhr, status, err) {
+ console.log([xhr,status, err])
+ });
+ },
+ fFormAskPass: function(msg) {
+ var root = this;
+
+ root.fInfo(msg);
+
+ $('input[type=password]').prop('disabled', false);
+ //$('input[type=password]').prop('required', true);
+ $('.auth-pass').show();
+ },
+ fFormError: function(data) {
+ var root = this;
+
+ root.fErr(data['msg']);
+ if (!('fields' in data)) {
+ return;
+ }
+
+ $.each(data['fields'], function(i, f) {
+ $('form .' + f).addClass('error');
+ });
+ },
+ fFormPostOk: function(data) {
+ if (!('url' in data)) {
+ root.fErr('Unable to redirect!')
+ }
+
+ window.location.href = data.url;
+ },
+
+ fInit: function(options) {
+ var root = this;
+
+ console.log('Initing nfsw...');
+
+ root.fFormInit();
+ },
+}
+
+$(document).ready(function() {
+ window.nfsw.fInit({});
+});