Browse Source

[TV] Create "Episode" class, "media.refresh" is now fired

pull/3730/merge
Dean Gardiner 11 years ago
parent
commit
ac857301ac
  1. 71
      couchpotato/core/media/show/_base/static/episode.js
  2. 130
      couchpotato/core/media/show/_base/static/show.episodes.js

71
couchpotato/core/media/show/_base/static/episode.js

@ -0,0 +1,71 @@
var Episode = new Class({
Extends: BlockBase,
action: {},
initialize: function(show, data){
var self = this;
self.show = show;
self.data = data;
self.el = new Element('div.item');
self.el_actions = new Element('div.actions');
self.create();
},
create: function(){
var self = this;
self.el.set('id', 'episode_'+self.data._id);
self.el.adopt(
new Element('span.episode', {'text': (self.data.info.number || 0)}),
new Element('span.name', {'text': self.getTitle()}),
new Element('span.firstaired', {'text': self.data.info.firstaired})
);
self.el_actions.inject(self.el);
if(self.data.identifiers && self.data.identifiers.imdb) {
new Element('a.imdb.icon2', {
'title': 'Go to the IMDB page of ' + self.show.getTitle(),
'href': 'http://www.imdb.com/title/' + self.data.identifiers.imdb + '/',
'target': '_blank'
}).inject(self.el_actions);
}
new Element('a.refresh.icon2', {
'title': 'Refresh the episode info and do a forced search',
'events': {
'click': self.doRefresh.bind(self)
}
}).inject(self.el_actions);
},
getTitle: function(){
var self = this;
var title = '';
if(self.data.info.titles && self.data.info.titles.length > 0) {
title = self.data.info.titles[0];
} else {
title = 'Episode ' + self.data.info.number;
}
return title;
},
doRefresh: function(e) {
var self = this;
Api.request('media.refresh', {
'data': {
'id': self.data._id
}
});
}
});

130
couchpotato/core/media/show/_base/static/show.episodes.js

@ -33,93 +33,71 @@ var Episodes = new Class({
createEpisodes: function() {
var self = this;
self.data.seasons.sort(function(a, b) {
// Move "Specials" to the bottom of the list
if(!a.info.number) {
return 1;
}
self.data.seasons.sort(self.sortSeasons);
self.data.seasons.each(function(season) {
self.createSeason(season);
if(!b.info.number) {
return -1;
}
season.episodes.sort(self.sortEpisodes);
season.episodes.each(function(episode) {
self.createEpisode(episode);
});
});
},
// Order seasons descending
if(a.info.number < b.info.number)
return -1;
createSeason: function(season) {
var self = this,
title = '';
if(a.info.number > b.info.number)
return 1;
if(season.info.number) {
title = 'Season ' + season.info.number;
} else {
// Season 0 / Specials
title = 'Specials';
}
return 0;
});
season['el'] = new Element('div', {
'class': 'item head',
'id': 'season_'+season._id
}).adopt(
new Element('span.name', {'text': title})
).inject(self.episodes_container);
},
self.data.seasons.each(function(season) {
var title = '';
if(season.info.number) {
title = 'Season ' + season.info.number;
} else {
// Season 0 / Specials
title = 'Specials';
}
season['el'] = new Element('div', {
'class': 'item head',
'id': 'season_'+season._id
}).adopt(
new Element('span.name', {'text': title})
).inject(self.episodes_container);
season.episodes.sort(function(a, b) {
// Order episodes descending
if(a.info.number < b.info.number)
return -1;
if(a.info.number > b.info.number)
return 1;
return 0;
});
createEpisode: function(episode){
var self = this,
e = new Episode(self.show, episode);
season.episodes.each(function(episode) {
var title = '';
$(e).inject(self.episodes_container);
},
if(episode.info.titles && episode.info.titles.length > 0) {
title = episode.info.titles[0];
} else {
title = 'Episode ' + episode.info.number;
}
sortSeasons: function(a, b) {
// Move "Specials" to the bottom of the list
if(!a.info.number) {
return 1;
}
episode['el'] = new Element('div', {
'class': 'item',
'id': 'episode_'+episode._id
}).adopt(
new Element('span.episode', {'text': (episode.info.number || 0)}),
new Element('span.name', {'text': title}),
new Element('span.firstaired', {'text': episode.info.firstaired})
).inject(self.episodes_container);
episode['el_actions'] = new Element('div.actions').inject(episode['el']);
if(episode.identifiers && episode.identifiers.imdb) {
new Element('a.imdb.icon2', {
'title': 'Go to the IMDB page of ' + self.show.getTitle(),
'href': 'http://www.imdb.com/title/' + episode.identifiers.imdb + '/',
'target': '_blank'
}).inject(episode['el_actions']);
}
if(!b.info.number) {
return -1;
}
new Element('a.refresh.icon2', {
'title': 'Refresh the episode info and do a forced search',
'events': {
'click': self.doRefresh.bind(self)
}
}).inject(episode['el_actions']);
});
});
// Order seasons descending
if(a.info.number < b.info.number)
return -1;
if(a.info.number > b.info.number)
return 1;
return 0;
},
doRefresh: function() {
sortEpisodes: function(a, b) {
// Order episodes descending
if(a.info.number < b.info.number)
return -1;
if(a.info.number > b.info.number)
return 1;
return 0;
}
});
Loading…
Cancel
Save