You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
4.2 KiB

var QualityBase = new Class({
tab: '',
content: '',
setup: function(data){
var self = this;
self.qualities = data.qualities;
14 years ago
self.profiles = {}
Object.each(data.profiles, self.createProfilesClass.bind(self));
App.addEvent('load', self.addSettings.bind(self))
},
14 years ago
getProfile: function(id){
return this.profiles[id]
},
// Hide items when getting profiles
getActiveProfiles: function(){
return Object.filter(this.profiles, function(profile){
return !profile.data.hide
});
},
getQuality: function(id){
return this.qualities.filter(function(q){
return q.id == id;
}).pick();
},
addSettings: function(){
var self = this;
self.settings = App.getPage('Settings')
self.settings.addEvent('create', function(){
var tab = self.settings.createTab('profile', {
'label': 'Quality',
'name': 'profile'
});
self.tab = tab.tab;
self.content = tab.content;
self.createProfiles();
14 years ago
self.createProfileOrdering();
self.createSizes();
})
},
/**
* Profiles
*/
createProfiles: function(){
var self = this;
self.settings.createGroup({
'label': 'Quality Profiles',
'description': 'Create your own profiles with multiple qualities.'
}).inject(self.content).adopt(
new Element('a.add_new_profile', {
'text': 'Create a new quality profile',
'events': {
14 years ago
'click': function(){
var profile = self.createProfilesClass();
$(profile).inject(self.profile_container, 'top')
}
}
}),
self.profile_container = new Element('div.container')
)
14 years ago
// Add profiles, that aren't part of the core (for editing)
14 years ago
Object.each(self.profiles, function(profile){
if(!profile.isCore())
$(profile).inject(self.profile_container, 'top')
})
},
14 years ago
createProfilesClass: function(data){
var self = this;
14 years ago
var data = data || {'id': randomString()}
return self.profiles[data.id] = new Profile(data);
},
createProfileOrdering: function(){
var self = this;
var profile_list;
var group = self.settings.createGroup({
'label': 'Profile Order',
'description': 'Change the order the profiles are in the dropdown list.'
}).adopt(
new Element('.ctrlHolder#profile_ordering').adopt(
new Element('label[text=Order]'),
new Element('.head').adopt(
new Element('span.show[text=Show]'),
new Element('span.profile_label[text=Profile]')
),
profile_list = new Element('ul')
)
).inject(self.content)
Object.each(self.profiles, function(profile){
var check;
new Element('li', {'data-id': profile.data.id}).adopt(
check = new Element('input.inlay[type=checkbox]', {
'checked': !profile.data.hide,
'events': {
'change': self.saveProfileOrdering.bind(self)
}
}),
new Element('span.profile_label', {
'text': profile.data.label
}),
new Element('span.handle')
).inject(profile_list);
new Form.Check(check);
});
// Sortable
self.profile_sortable = new Sortables(profile_list, {
'revert': true,
'handle': '',
'opacity': 0.5,
'onComplete': self.saveProfileOrdering.bind(self)
});
},
saveProfileOrdering: function(){
var self = this;
var ids = [];
var hidden = [];
self.profile_sortable.list.getElements('li').each(function(el, nr){
ids.include(el.get('data-id'));
hidden[nr] = +!el.getElement('input[type=checkbox]').get('checked');
});
p(ids, hidden);
Api.request('profile.save_order', {
'data': {
'ids': ids,
'hidden': hidden
14 years ago
}
14 years ago
});
},
/**
* Sizes
*/
createSizes: function(){
var self = this;
var group = self.settings.createGroup({
'label': 'Sizes',
'description': 'Edit the minimal and maximum sizes (in MB) for each quality.',
'advanced': true
}).inject(self.content)
14 years ago
new Element('div.item.head').adopt(
new Element('span.label', {'text': 'Quality'}),
new Element('span.min', {'text': 'Min'}),
new Element('span.max', {'text': 'Max'})
).inject(group)
14 years ago
Object.each(self.qualities, function(quality){
14 years ago
new Element('div.ctrlHolder.item').adopt(
new Element('span.label', {'text': quality.label}),
new Element('input.min', {'value': quality.size_min}),
new Element('input.max', {'value': quality.size_max})
).inject(group)
});
14 years ago
}
});
window.Quality = new QualityBase();