summaryrefslogtreecommitdiffstats
path: root/pyload/web/app/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'pyload/web/app/scripts')
-rw-r--r--pyload/web/app/scripts/models/Setup.js20
-rw-r--r--pyload/web/app/scripts/views/setup/finishedView.js25
-rw-r--r--pyload/web/app/scripts/views/setup/setupView.js52
-rw-r--r--pyload/web/app/scripts/views/setup/systemView.js5
-rw-r--r--pyload/web/app/scripts/views/setup/userView.js39
-rw-r--r--pyload/web/app/scripts/views/setup/welcomeView.js5
6 files changed, 136 insertions, 10 deletions
diff --git a/pyload/web/app/scripts/models/Setup.js b/pyload/web/app/scripts/models/Setup.js
index 82a2978db..424edf452 100644
--- a/pyload/web/app/scripts/models/Setup.js
+++ b/pyload/web/app/scripts/models/Setup.js
@@ -4,10 +4,30 @@ define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'],
return Backbone.Model.extend({
+ url: App.apiUrl('setup'),
defaults: {
lang: 'en',
+ system: null,
+ deps: null,
user: null,
password: null
+ },
+
+ fetch: function(options) {
+ options || (options = {});
+ options.url = App.apiUrl('setup');
+ return Backbone.Model.prototype.fetch.call(this, options);
+ },
+
+ // will get a 409 on success
+ submit: function(options) {
+ options || (options = {});
+ options.url = App.apiUrl('setup_done');
+ options.data = {
+ user: this.get('user'),
+ password: this.get('password')
+ };
+ return Backbone.Model.prototype.fetch.call(this, options);
}
});
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');
}
});