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/default.js18
-rw-r--r--pyload/web/app/scripts/helpers/ifEq.js14
-rw-r--r--pyload/web/app/scripts/models/Setup.js14
-rw-r--r--pyload/web/app/scripts/setup.js33
-rw-r--r--pyload/web/app/scripts/views/setup/setupView.js89
-rw-r--r--pyload/web/app/scripts/views/setup/systemView.js20
-rw-r--r--pyload/web/app/scripts/views/setup/welcomeView.js20
7 files changed, 203 insertions, 5 deletions
diff --git a/pyload/web/app/scripts/default.js b/pyload/web/app/scripts/default.js
index 428ec2b28..91b46715e 100644
--- a/pyload/web/app/scripts/default.js
+++ b/pyload/web/app/scripts/default.js
@@ -1,5 +1,5 @@
-define('default', ['backbone', 'jquery', 'app', 'router', 'models/UserSession'],
- function(Backbone, $, App, Router, UserSession) {
+define('default', ['require', 'backbone', 'jquery', 'app', 'router', 'models/UserSession'],
+ function(require, Backbone, $, App, Router, UserSession) {
'use strict';
// Global ajax options
@@ -21,9 +21,17 @@ define('default', ['backbone', 'jquery', 'app', 'router', 'models/UserSession'],
};
$(function() {
- App.user = new UserSession();
- App.router = new Router();
- App.start();
+ // load setup async
+ if (window.setup === 'true') {
+ require(['setup'], function(SetupRouter) {
+ App.router = new SetupRouter();
+ App.start();
+ });
+ } else {
+ App.user = new UserSession();
+ App.router = new Router();
+ App.start();
+ }
});
return App;
diff --git a/pyload/web/app/scripts/helpers/ifEq.js b/pyload/web/app/scripts/helpers/ifEq.js
new file mode 100644
index 000000000..1c8a71b61
--- /dev/null
+++ b/pyload/web/app/scripts/helpers/ifEq.js
@@ -0,0 +1,14 @@
+define('helpers/ifEq', ['underscore', 'handlebars'],
+ function(_, Handlebars) {
+ /*jshint validthis:true */
+ 'use strict';
+ function ifEq(v1, v2, options) {
+ if (v1 === v2) {
+ return options.fn(this);
+ }
+ return options.inverse(this);
+ }
+
+ Handlebars.registerHelper('ifEq', ifEq);
+ return ifEq;
+ });
diff --git a/pyload/web/app/scripts/models/Setup.js b/pyload/web/app/scripts/models/Setup.js
new file mode 100644
index 000000000..82a2978db
--- /dev/null
+++ b/pyload/web/app/scripts/models/Setup.js
@@ -0,0 +1,14 @@
+define(['jquery', 'backbone', 'underscore', 'app', 'utils/apitypes'],
+ function($, Backbone, _, App, Api) {
+ 'use strict';
+
+ return Backbone.Model.extend({
+
+ defaults: {
+ lang: 'en',
+ user: null,
+ password: null
+ }
+
+ });
+ }); \ No newline at end of file
diff --git a/pyload/web/app/scripts/setup.js b/pyload/web/app/scripts/setup.js
new file mode 100644
index 000000000..94d370078
--- /dev/null
+++ b/pyload/web/app/scripts/setup.js
@@ -0,0 +1,33 @@
+/**
+ * Router and controller used in setup mode
+ */
+define([
+ // Libraries
+ 'backbone',
+ 'marionette',
+ 'app',
+
+ // Views
+ 'views/setup/setupView'
+],
+ function(Backbone, Marionette, App, SetupView) {
+ 'use strict';
+
+ return Backbone.Marionette.AppRouter.extend({
+
+ appRoutes: {
+ '': 'setup'
+ },
+
+ controller: {
+
+ setup: function() {
+
+ var view = new SetupView();
+ App.actionbar.show(new view.actionbar());
+ App.content.show(view);
+ }
+
+ }
+ });
+ });
diff --git a/pyload/web/app/scripts/views/setup/setupView.js b/pyload/web/app/scripts/views/setup/setupView.js
new file mode 100644
index 000000000..7636a0bc2
--- /dev/null
+++ b/pyload/web/app/scripts/views/setup/setupView.js
@@ -0,0 +1,89 @@
+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) {
+ 'use strict';
+
+ return Backbone.Marionette.ItemView.extend({
+ template: template,
+
+ events: {
+ },
+
+ ui: {
+ page: '.setup-page'
+ },
+
+ pages: [
+ welcomeView,
+ systemView
+ ],
+
+ page: 0,
+ view: null,
+
+ initialize: function() {
+ var self = this;
+ this.model = new Setup();
+
+ this.actionbar = Backbone.Marionette.ItemView.extend({
+ template: templateBar,
+ view: this,
+ events: {
+ 'click .select-page': 'selectPage'
+ },
+
+ initialize: function() {
+ this.listenTo(self.model, 'page:changed', this.render);
+ },
+
+ serializeData: function() {
+ return {
+ page: this.view.page,
+ max: this.view.pages.length - 1,
+ pages: _.map(this.view.pages, function(p) {
+ return p.prototype.name;
+ })
+ };
+ },
+
+ selectPage: function(e) {
+ this.view.openPage(parseInt($(e.target).data('page'), 10));
+ }
+
+ });
+ this.listenTo(this.model, 'page:next', function() {
+ self.openPage(self.page++);
+ });
+ this.listenTo(this.model, 'page:prev', function() {
+ self.openPage(self.page--);
+ });
+ },
+
+ openPage: function(page) {
+ console.log('Change page', page);
+ // check if number is reasonable
+ if (!_.isNumber(page) || !_.isFinite(page))
+ return;
+
+ if (page === this.page)
+ return;
+
+ this.page = page;
+ this.onRender();
+
+ this.model.trigger('page:changed', page);
+ },
+
+ onRender: function() {
+ // close old opened view
+ if (this.view)
+ this.view.close();
+
+ // TODO: animation
+ this.view = new this.pages[this.page]({model: this.model});
+ this.ui.page.empty();
+ this.ui.page.append(this.view.render().$el);
+ }
+
+ });
+ }); \ No newline at end of file
diff --git a/pyload/web/app/scripts/views/setup/systemView.js b/pyload/web/app/scripts/views/setup/systemView.js
new file mode 100644
index 000000000..11e50213d
--- /dev/null
+++ b/pyload/web/app/scripts/views/setup/systemView.js
@@ -0,0 +1,20 @@
+define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/setup/system'],
+ function($, Backbone, _, App, template) {
+ 'use strict';
+
+ return Backbone.Marionette.ItemView.extend({
+
+ name: 'System',
+ template: template,
+
+ events: {
+ },
+
+ ui: {
+ },
+
+ onRender: function() {
+ }
+
+ });
+ }); \ 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
new file mode 100644
index 000000000..4affc9075
--- /dev/null
+++ b/pyload/web/app/scripts/views/setup/welcomeView.js
@@ -0,0 +1,20 @@
+define(['jquery', 'backbone', 'underscore', 'app', 'hbs!tpl/setup/welcome'],
+ function($, Backbone, _, App, template) {
+ 'use strict';
+
+ return Backbone.Marionette.ItemView.extend({
+
+ name: 'Language',
+ template: template,
+
+ events: {
+ },
+
+ ui: {
+ },
+
+ onRender: function() {
+ }
+
+ });
+ }); \ No newline at end of file