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.

291 lines
5.9 KiB

Page.Wanted = new Class({
Extends: PageBase,
name: 'wanted',
title: 'Gimmy gimmy gimmy!',
indexAction: function(param){
var self = this;
if(!self.wanted){
// Wanted movies
self.wanted = new MovieList({
'status': 'active',
13 years ago
'navigation': true,
'actions': MovieActions
});
$(self.wanted).inject(self.el);
App.addEvent('library.update', self.wanted.update.bind(self.wanted));
}
14 years ago
}
});
var MovieActions = {};
14 years ago
window.addEvent('domready', function(){
MovieActions.Wanted = {
'IMBD': IMDBAction
,'releases': ReleaseAction
14 years ago
14 years ago
,'Edit': new Class({
14 years ago
14 years ago
Extends: MovieAction,
14 years ago
14 years ago
create: function(){
var self = this;
14 years ago
14 years ago
self.el = new Element('a.edit', {
'title': 'Change movie information, like title and quality.',
14 years ago
'events': {
'click': self.editMovie.bind(self)
}
});
14 years ago
14 years ago
},
14 years ago
14 years ago
editMovie: function(e){
var self = this;
(e).stop();
14 years ago
14 years ago
if(!self.options_container){
self.options_container = new Element('div.options').adopt(
13 years ago
new Element('div.form').adopt(
14 years ago
self.title_select = new Element('select', {
'name': 'title'
}),
self.profile_select = new Element('select', {
'name': 'profile'
}),
new Element('a.button.edit', {
'text': 'Save',
'events': {
'click': self.save.bind(self)
}
})
)
).inject(self.movie, 'top');
14 years ago
14 years ago
Array.each(self.movie.data.library.titles, function(alt){
new Element('option', {
'text': alt.title
}).inject(self.title_select);
});
14 years ago
14 years ago
Object.each(Quality.getActiveProfiles(), function(profile){
new Element('option', {
'value': profile.id ? profile.id : profile.data.id,
'text': profile.label ? profile.label : profile.data.label
}).inject(self.profile_select);
14 years ago
self.profile_select.set('value', (self.movie.profile || {})['id']);
14 years ago
});
14 years ago
}
self.movie.slide('in', self.options_container);
14 years ago
},
14 years ago
14 years ago
save: function(e){
(e).stop();
var self = this;
14 years ago
14 years ago
Api.request('movie.edit', {
'data': {
'id': self.movie.get('id'),
'default_title': self.title_select.get('value'),
'profile_id': self.profile_select.get('value')
},
'useSpinner': true,
'spinnerTarget': $(self.movie),
'onComplete': function(){
self.movie.quality.set('text', self.profile_select.getSelected()[0].get('text'));
self.movie.title.set('text', self.title_select.getSelected()[0].get('text'));
}
});
14 years ago
14 years ago
self.movie.slide('out');
}
14 years ago
14 years ago
})
14 years ago
14 years ago
,'Refresh': new Class({
14 years ago
14 years ago
Extends: MovieAction,
14 years ago
14 years ago
create: function(){
var self = this;
14 years ago
14 years ago
self.el = new Element('a.refresh', {
'title': 'Refresh the movie info and do a forced search',
'events': {
14 years ago
'click': self.doRefresh.bind(self)
14 years ago
}
});
14 years ago
14 years ago
},
14 years ago
doRefresh: function(e){
14 years ago
var self = this;
(e).stop();
14 years ago
14 years ago
Api.request('movie.refresh', {
'data': {
'id': self.movie.get('id')
}
});
}
14 years ago
14 years ago
})
14 years ago
14 years ago
,'Delete': new Class({
14 years ago
14 years ago
Extends: MovieAction,
14 years ago
14 years ago
Implements: [Chain],
14 years ago
14 years ago
create: function(){
var self = this;
14 years ago
14 years ago
self.el = new Element('a.delete', {
'title': 'Remove the movie from your wanted list',
'events': {
'click': self.showConfirm.bind(self)
}
});
14 years ago
14 years ago
},
14 years ago
14 years ago
showConfirm: function(e){
var self = this;
(e).stop();
14 years ago
14 years ago
if(!self.delete_container){
13 years ago
self.delete_container = new Element('div.delete_container').adopt(
14 years ago
new Element('a.cancel', {
'text': 'Cancel',
'events': {
'click': self.hideConfirm.bind(self)
}
}),
14 years ago
new Element('span.or', {
'text': 'or'
}),
14 years ago
new Element('a.button.delete', {
'text': 'Delete ' + self.movie.title.get('text'),
'events': {
14 years ago
'click': self.del.bind(self)
}
})
14 years ago
).inject(self.movie, 'top');
}
self.movie.slide('in', self.delete_container);
14 years ago
},
14 years ago
14 years ago
hideConfirm: function(e){
var self = this;
(e).stop();
14 years ago
14 years ago
self.movie.slide('out');
},
14 years ago
14 years ago
del: function(e){
(e).stop();
var self = this;
14 years ago
14 years ago
var movie = $(self.movie);
14 years ago
14 years ago
self.chain(
function(){
self.callChain();
},
function(){
Api.request('movie.delete', {
'data': {
'id': self.movie.get('id')
},
'onComplete': function(){
movie.set('tween', {
'onComplete': function(){
movie.destroy();
}
});
movie.tween('height', 0);
}
});
}
14 years ago
);
14 years ago
14 years ago
self.callChain();
14 years ago
14 years ago
}
14 years ago
14 years ago
})
};
14 years ago
14 years ago
MovieActions.Snatched = {
'IMBD': IMDBAction
,'Delete': MovieActions.Wanted.Delete
};
14 years ago
MovieActions.Done = {
'IMBD': IMDBAction
,'Edit': MovieActions.Wanted.Edit
,'Files': new Class({
Extends: MovieAction,
create: function(){
var self = this;
self.el = new Element('a.files', {
'title': 'Available files',
'events': {
'click': self.showFiles.bind(self)
}
});
},
showFiles: function(e){
var self = this;
(e).stop();
if(!self.options_container){
self.options_container = new Element('div.options').adopt(
self.files_container = new Element('div.files.table')
14 years ago
).inject(self.movie, 'top');
// Header
new Element('div.item.head').adopt(
new Element('span.name', {'text': 'File'}),
new Element('span.type', {'text': 'Type'}),
new Element('span.is_available', {'text': 'Available'})
).inject(self.files_container)
14 years ago
Array.each(self.movie.data.releases, function(release){
var rel = new Element('div.release').inject(self.files_container);
14 years ago
Array.each(release.files, function(file){
13 years ago
new Element('div.file.item').adopt(
14 years ago
new Element('span.name', {'text': file.path}),
new Element('span.type', {'text': File.Type.get(file.type_id).name}),
new Element('span.available', {'text': file.available})
).inject(rel)
});
});
}
self.movie.slide('in', self.options_container);
},
})
};
14 years ago
})