diff options
author | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-10-03 19:21:05 +0200 |
---|---|---|
committer | RaNaN <Mast3rRaNaN@hotmail.de> | 2013-10-03 19:21:05 +0200 |
commit | a8d3e8341eee6af4c778f512d7f8584c476d49fe (patch) | |
tree | 777681f695f64488c4aa5e869cf937112077befc /pyload/web/app/scripts/views | |
parent | small bug fixes (diff) | |
download | pyload-a8d3e8341eee6af4c778f512d7f8584c476d49fe.tar.xz |
basically working web setup
Diffstat (limited to 'pyload/web/app/scripts/views')
-rw-r--r-- | pyload/web/app/scripts/views/setup/finishedView.js | 25 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/setup/setupView.js | 52 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/setup/systemView.js | 5 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/setup/userView.js | 39 | ||||
-rw-r--r-- | pyload/web/app/scripts/views/setup/welcomeView.js | 5 |
5 files changed, 116 insertions, 10 deletions
diff --git a/pyload/web/app/scripts/views/setup/finishedView.js b/pyload/web/app/scripts/views/setup/finishedView.js new file mode 100644 index 000000000..9f0f8db19 --- /dev/null +++ b/pyload/web/app/scripts/views/setup/finishedView.js @@ -0,0 +1,25 @@ +define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/setup/finished'], + function($, Backbone, _, App, template) { + 'use strict'; + + return Backbone.Marionette.ItemView.extend({ + + name: 'Finished', + template: template, + + events: { + 'click .btn-blue': 'confirm' + }, + + ui: { + }, + + onRender: function() { + }, + + confirm: function() { + this.model.submit(); + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/setup/setupView.js b/pyload/web/app/scripts/views/setup/setupView.js index 7636a0bc2..8ab6fba51 100644 --- a/pyload/web/app/scripts/views/setup/setupView.js +++ b/pyload/web/app/scripts/views/setup/setupView.js @@ -1,6 +1,6 @@ -define(['jquery', 'backbone', 'underscore', 'app', 'models/Setup', 'hbs!tpl/setup/layout', 'hbs!tpl/setup/actionbar', - './welcomeView', './systemView'], - function($, Backbone, _, App, Setup, template, templateBar, welcomeView, systemView) { +define(['jquery', 'backbone', 'underscore', 'app', 'models/Setup', 'hbs!tpl/setup/layout', 'hbs!tpl/setup/actionbar', 'hbs!tpl/setup/error', + './welcomeView', './systemView', './userView', './finishedView'], + function($, Backbone, _, App, Setup, template, templateBar, templateError, welcomeView, systemView, userView, finishedView) { 'use strict'; return Backbone.Marionette.ItemView.extend({ @@ -15,11 +15,14 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/Setup', 'hbs!tpl/setu pages: [ welcomeView, - systemView + systemView, + userView, + finishedView ], page: 0, view: null, + error: null, initialize: function() { var self = this; @@ -52,37 +55,66 @@ define(['jquery', 'backbone', 'underscore', 'app', 'models/Setup', 'hbs!tpl/setu }); this.listenTo(this.model, 'page:next', function() { - self.openPage(self.page++); + self.openPage(self.page + 1); }); this.listenTo(this.model, 'page:prev', function() { - self.openPage(self.page--); + self.openPage(self.page - 1); }); + + this.listenTo(this.model, 'error', this.onError); + this.model.fetch(); }, openPage: function(page) { console.log('Change page', page); // check if number is reasonable - if (!_.isNumber(page) || !_.isFinite(page)) + if (!_.isNumber(page) || !_.isFinite(page) || page < 0 || page >= this.pages.length) return; if (page === this.page) return; + // Render error directly + if (this.error) { + this.onRender(); + return; + } + this.page = page; - this.onRender(); + + var self = this; + this.ui.page.fadeOut({complete: function() { + self.onRender(); + }}); this.model.trigger('page:changed', page); }, + onError: function(model, xhr) { + console.log('Setup error', xhr); + this.error = xhr; + this.onRender(); + }, + onRender: function() { + // close old opened view if (this.view) this.view.close(); - // TODO: animation + // Render error if occurred + if (this.error) { + this.ui.page.html(templateError(this.error)); + return; + } + this.view = new this.pages[this.page]({model: this.model}); this.ui.page.empty(); - this.ui.page.append(this.view.render().$el); + + var el = this.view.render().el; + this.ui.page.append(el); + + this.ui.page.fadeIn(); } }); diff --git a/pyload/web/app/scripts/views/setup/systemView.js b/pyload/web/app/scripts/views/setup/systemView.js index 11e50213d..b4c0f7e12 100644 --- a/pyload/web/app/scripts/views/setup/systemView.js +++ b/pyload/web/app/scripts/views/setup/systemView.js @@ -8,12 +8,17 @@ define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/setup/system'], template: template, events: { + 'click .btn-blue': 'nextPage' }, ui: { }, onRender: function() { + }, + + nextPage: function() { + this.model.trigger('page:next'); } }); diff --git a/pyload/web/app/scripts/views/setup/userView.js b/pyload/web/app/scripts/views/setup/userView.js new file mode 100644 index 000000000..95eaa0dc2 --- /dev/null +++ b/pyload/web/app/scripts/views/setup/userView.js @@ -0,0 +1,39 @@ +define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/setup/user'], + function($, Backbone, _, App, template) { + 'use strict'; + + return Backbone.Marionette.ItemView.extend({ + + name: 'User', + template: template, + + events: { + 'click .btn-blue': 'submit' + }, + + ui: { + username: '#username', + password: '#password', + password2: '#password2' + }, + + onRender: function() { + }, + + submit: function() { + var pw = this.ui.password.val(); + var pw2 = this.ui.password2.val(); + + // TODO more checks and error messages + if (pw !== pw2) { + return; + } + + this.model.set('user', this.ui.username.val()); + this.model.set('password', pw); + + this.model.trigger('page:next'); + } + + }); + });
\ No newline at end of file diff --git a/pyload/web/app/scripts/views/setup/welcomeView.js b/pyload/web/app/scripts/views/setup/welcomeView.js index 4affc9075..a964e0d42 100644 --- a/pyload/web/app/scripts/views/setup/welcomeView.js +++ b/pyload/web/app/scripts/views/setup/welcomeView.js @@ -8,12 +8,17 @@ define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/setup/welcome'], template: template, events: { + 'click .btn-blue': 'nextPage' }, ui: { }, onRender: function() { + }, + + nextPage: function() { + this.model.trigger('page:next'); } }); |