Reordering of settings

This commit is contained in:
Ruud
2012-03-04 23:26:36 +01:00
parent ca67370b44
commit f160bfe779
36 changed files with 370 additions and 176 deletions
+54
View File
@@ -0,0 +1,54 @@
Block.More = new Class({
Extends: BlockBase,
create: function(){
var self = this;
self.el = new Element('div.more_menu').adopt(
self.more_option_ul = new Element('ul').adopt(
new Element('li').adopt(
new Element('a.orange', {
'text': 'Restart',
'events': {
'click': App.restart.bind(App)
}
})
),
new Element('li').adopt(
new Element('a.red', {
'text': 'Shutdown',
'events': {
'click': App.shutdown.bind(App)
}
})
)
),
new Element('a.button.onlay', {
'events': {
'click': function(){
self.more_option_ul.toggleClass('show')
if(self.more_option_ul.hasClass('show'))
this.addEvent('outerClick', function(){
self.more_option_ul.removeClass('show')
this.removeEvents('outerClick');
})
else
this.removeEvents('outerClick');
}
}
})
)
},
addLink: function(tab, position){
var self = this
return new Element('li').adopt(tab).inject(self.more_option_ul, position || 'bottom')
}
});
+10 -6
View File
@@ -59,13 +59,14 @@ var CouchPotato = new Class({
$(self.block.header).addClass('header').adopt(
new Element('div').adopt(
self.block.navigation = new Block.Navigation(self, {}),
self.block.search = new Block.Search(self, {})
self.block.search = new Block.Search(self, {}),
self.block.more = new Block.More(self, {})
)
),
self.content = new Element('div.content'),
self.block.footer = new Block.Footer(self, {})
);
new ScrollSpy({
min: 10,
onLeave: function(){
@@ -108,7 +109,7 @@ var CouchPotato = new Class({
try {
var page = self.pages[page_name] || self.pages.Wanted;
page.open(action, params);
page.open(action, params, current_url);
page.show();
}
catch(e){
@@ -150,7 +151,7 @@ var CouchPotato = new Class({
var self = this;
(function(){
Api.request('app.available', {
'onFailure': function(){
self.checkAvailable.delay(1000, self);
@@ -161,7 +162,7 @@ var CouchPotato = new Class({
self.fireEvent('load');
}
});
}).delay(delay || 0)
},
@@ -214,7 +215,7 @@ var Route = new Class({
self.page = (url.length > 0) ? url.shift() : self.defaults.page
self.action = (url.length > 0) ? url.shift() : self.defaults.action
self.params = self.defaults.params
self.params = Object.merge({}, self.defaults.params);
if(url.length > 1){
var key
url.each(function(el, nr){
@@ -226,6 +227,9 @@ var Route = new Class({
}
})
}
else if(url.length == 1){
self.params[url] = true;
}
return self
},
+30 -50
View File
@@ -38,6 +38,36 @@ var AboutSettingTab = new Class({
today = new Date(),
one_day = 1000*60*60*24;
self.settings.createGroup({
'label': 'About This CouchPotato',
'name': 'variables'
}).inject(self.content).adopt(
new Element('dl.info').adopt(
new Element('dt[text=Version]'),
self.version_text = new Element('dd.version', {
'text': 'Getting version...',
'events': {
'click': self.checkForUpdate.bind(self),
'mouseenter': function(){
this.set('text', 'Check for updates')
},
'mouseleave': function(){
self.fillVersion(Updater.getInfo())
}
}
}),
new Element('dt[text=Directories]'),
new Element('dd', {'text': App.getOption('app_dir')}),
new Element('dd', {'text': App.getOption('data_dir')}),
new Element('dt[text=Startup Args]'),
new Element('dd', {'html': App.getOption('args')}),
new Element('dd', {'html': App.getOption('options')})
)
);
if(!self.fillVersion(Updater.getInfo()))
Updater.addEvent('loaded', self.fillVersion.bind(self))
self.settings.createGroup({
'name': 'Help Support CouchPotato'
}).inject(self.content).adopt(
@@ -78,56 +108,6 @@ var AboutSettingTab = new Class({
})
);
self.settings.createGroup({
'label': 'About This CouchPotato',
'name': 'variables'
}).inject(self.content).adopt(
new Element('dl.info').adopt(
new Element('dt[text=Version]'),
self.version_text = new Element('dd.version', {
'text': 'Getting version...',
'events': {
'click': self.checkForUpdate.bind(self),
'mouseenter': function(){
this.set('text', 'Check for updates')
},
'mouseleave': function(){
self.fillVersion(Updater.getInfo())
}
}
}),
new Element('dt[text=Directories]'),
new Element('dd', {'text': App.getOption('app_dir')}),
new Element('dd', {'text': App.getOption('data_dir')}),
new Element('dt[text=Startup Args]'),
new Element('dd', {'html': App.getOption('args')}),
new Element('dd', {'html': App.getOption('options')})
)
);
if(!self.fillVersion(Updater.getInfo()))
Updater.addEvent('loaded', self.fillVersion.bind(self))
self.settings.createGroup({
'name': 'actions'
}).inject(self.content).adopt(
new Element('div').adopt(
new Element('a.button.red', {
'text': 'Shutdown',
'events': {
'click': App.shutdown.bind(App)
}
}),
new Element('a.button.orange', {
'text': 'Restart',
'events': {
'click': App.restart.bind(App)
}
})
)
);
},
fillVersion: function(json){
+90 -3
View File
@@ -8,6 +8,21 @@ Page.Settings = new Class({
tabs: {},
current: 'about',
has_tab: false,
initialize: function(options){
var self = this;
self.parent(options);
// Add to more menu
if(self.name == 'settings')
App.getBlock('more').addLink(new Element('a', {
'href': App.createUrl(self.name),
'text': self.name.capitalize(),
'title': self.title
}), 'top')
},
open: function(action, params){
var self = this;
@@ -40,8 +55,26 @@ Page.Settings = new Class({
var c = 'active';
var t = self.tabs[tab_name] || self.tabs[self.action] || self.tabs.general;
// Subtab
var subtab = null
Object.each(self.params, function(param, subtab_name){
subtab = subtab_name;
})
self.el.getElements('li.'+c+' , .tab_content.'+c).each(function(active){
active.removeClass(c);
});
if (t.subtabs[subtab]){
t.tab[a](c);
t.subtabs[subtab].tab[a](c);
t.subtabs[subtab].content[a](c);
}
else {
t.tab[a](c);
t.content[a](c);
}
return t
},
@@ -107,10 +140,20 @@ Page.Settings = new Class({
new Form.Check(self.advanced_toggle);
// Add content to tabs
var options = [];
Object.each(json.options, function(section, section_name){
section['section_name'] = section_name;
options.include(section);
})
options.sort(function(a, b){
return (a.order || 100) - (b.order || 100)
}).each(function(section){
var section_name = section.section_name;
// Add groups to content
section.groups.sortBy('order').each(function(group){
if(group.hidden) return;
if(self.wizard_only && !group.wizard)
return;
@@ -118,17 +161,28 @@ Page.Settings = new Class({
// Create tab
if(!self.tabs[group.tab] || !self.tabs[group.tab].groups)
self.createTab(group.tab, {});
var content_container = self.tabs[group.tab].content
// Create subtab
if(group.subtab){
if (!self.tabs[group.tab].subtabs[group.subtab])
self.createSubTab(group.subtab, {}, self.tabs[group.tab], group.tab);
var content_container = self.tabs[group.tab].subtabs[group.subtab].content
}
// Create the group
if(!self.tabs[group.tab].groups[group.name]){
var group_el = self.createGroup(group)
.inject(self.tabs[group.tab].content)
.inject(content_container)
.addClass('section_'+section_name);
self.tabs[group.tab].groups[group.name] = group_el
}
// Add options to group
group.options.sortBy('order').each(function(option){
group.options.sort(function(a, b){
return (a.order || 100) - (b.order || 100)
}).each(function(option){
if(option.hidden) return;
var class_name = (option.type || 'string').capitalize();
var input = new Option[class_name](section_name, option.name, self.getValue(section_name, option.name), option);
input.inject(self.tabs[group.tab].groups[group.name]);
@@ -164,6 +218,7 @@ Page.Settings = new Class({
self.tabs[tab_name] = Object.merge(self.tabs[tab_name], {
'tab': tab_el,
'subtabs': {},
'content': new Element('div.tab_content.tab_'+tab_name).inject(self.containers),
'groups': {}
})
@@ -172,11 +227,43 @@ Page.Settings = new Class({
},
createSubTab: function(tab_name, tab, parent_tab, parent_tab_name){
var self = this;
if(parent_tab.subtabs[tab_name])
return parent_tab.subtabs[tab_name]
if(!parent_tab.subtabs_el)
parent_tab.subtabs_el = new Element('ul.subtabs').inject(parent_tab.tab);
var label = (tab.label || tab.name || tab_name).capitalize()
var tab_el = new Element('li.t_'+tab_name).adopt(
new Element('a', {
'href': App.createUrl(self.name+'/'+parent_tab_name+'/'+tab_name),
'text': label
}).adopt()
).inject(parent_tab.subtabs_el);
if(!parent_tab.subtabs[tab_name])
parent_tab.subtabs[tab_name] = {
'label': label
}
parent_tab.subtabs[tab_name] = Object.merge(parent_tab.subtabs[tab_name], {
'tab': tab_el,
'content': new Element('div.tab_content.tab_'+tab_name).inject(self.containers),
'groups': {}
});
return parent_tab.subtabs[tab_name]
},
createGroup: function(group){
var self = this;
var group_el = new Element('fieldset', {
'class': (group.advanced ? 'inlineLabels advanced' : 'inlineLabels') + ' group_' + (group.name || '')
'class': (group.advanced ? 'inlineLabels advanced' : 'inlineLabels') + ' group_' + (group.name || '') + ' subtab_' + (group.subtab || '')
}).adopt(
new Element('h2', {
'text': (group.label || group.name).capitalize()