mirror of
https://github.com/fergalmoran/dss.git
synced 2026-01-04 07:54:29 +00:00
257 lines
8.2 KiB
JavaScript
257 lines
8.2 KiB
JavaScript
/** @license
|
|
|
|
----------------------------------------------
|
|
|
|
Copyright (c) 2012, Fergal Moran. All rights reserved.
|
|
Code provided under the BSD License:
|
|
|
|
*/
|
|
var AppRouter = Backbone.Router.extend({
|
|
routes:{
|
|
"mixes":"mixList",
|
|
"mixes/:type":"mixList",
|
|
"mix/upload":"mixUpload",
|
|
"mix/:id":"mixDetails",
|
|
"mix/edit/:id":"mixEdit",
|
|
"releases":"releaseList",
|
|
"release/add":"releaseAdd",
|
|
"release/edit/:id":"releaseEdit",
|
|
"release/:id":"releaseDetails",
|
|
"events":"eventList",
|
|
"event/add":"eventAdd",
|
|
"event/:id":"eventDetails",
|
|
"accounts/social/connections/":"connectAccounts",
|
|
"accounts/facebook/login":"loginRedirect",
|
|
"accounts/twitter/login":"loginRedirect",
|
|
"accounts/login/":"login",
|
|
"accounts/logout/":"logout",
|
|
"user/:id":"user",
|
|
"upload/":"defaultRoute",
|
|
"me":"userDetails",
|
|
"*path":"defaultRoute"
|
|
},
|
|
initialize:function () {
|
|
this.headerView = new HeaderView();
|
|
$('#header').html(this.headerView.el);
|
|
$('#site-content-fill').html('');
|
|
this.bind('all', this.trackPageView);
|
|
|
|
},
|
|
trackPageView:function () {
|
|
var url;
|
|
url = Backbone.history.getFragment();
|
|
return com.podnoms.utils.trackPageView(url);
|
|
},
|
|
defaultRoute:function (path) {
|
|
if (path == undefined || path == "" || path == "/")
|
|
this.mixList('latest');
|
|
else {
|
|
$.get('/tpl/404/', function (data) {
|
|
$('#content').html(_.template(data));
|
|
});
|
|
|
|
}
|
|
},
|
|
user:function (user) {
|
|
this._renderMixList('latest', { "user":user });
|
|
},
|
|
mixList:function (type) {
|
|
this._renderMixList(type);
|
|
},
|
|
_renderMixList:function (type, data) {
|
|
var mixList = new MixCollection();
|
|
mixList.type = type || 'latest';
|
|
$('#site-content-fill').html('');
|
|
|
|
var payload = $.extend(type != undefined ? {type:type} : null, data);
|
|
mixList.fetch({
|
|
data:payload,
|
|
success:function () {
|
|
var mixes = new MixListView({
|
|
collection:mixList
|
|
});
|
|
var content = mixes.el;
|
|
$('#content').html(content);
|
|
if (mixes.itemPlaying != null) {
|
|
com.podnoms.settings.setupPlayer(mixes.itemPlaying.toJSON(), mixes.itemPlaying.get('id'));
|
|
}
|
|
}
|
|
});
|
|
this.sidebarView = new SidebarView();
|
|
$('#sidebar').html(this.sidebarView.el);
|
|
startChat(
|
|
$('#chat-messages-body', this.sidebarView.el),
|
|
$('#input', this.sidebarView.el),
|
|
$('#status', this.sidebarView.el),
|
|
$('#header-profile-edit').text());
|
|
},
|
|
mixDetails:function (id) {
|
|
var mix = new Mix({
|
|
id:id
|
|
});
|
|
mix.fetch({
|
|
success:function () {
|
|
var html = new MixView({
|
|
model:mix
|
|
});
|
|
$('#content').html(html.el);
|
|
$('#site-content-fill').html('');
|
|
|
|
if (com.podnoms.player.isPlayingId(mix.get('id'))) {
|
|
com.podnoms.settings.setupPlayer(mix.toJSON(), mix.get('id'));
|
|
}
|
|
}
|
|
});
|
|
},
|
|
mixUpload:function () {
|
|
var html = new MixCreateView({
|
|
model:new Mix()
|
|
});
|
|
$('#content').html(html.el);
|
|
$('#site-content-fill').html('');
|
|
},
|
|
mixEdit:function (id) {
|
|
var mix = new Mix({
|
|
id:id
|
|
});
|
|
mix.fetch({
|
|
success:function () {
|
|
var html = new MixCreateView({
|
|
model:mix
|
|
});
|
|
$('#content').html(html.el);
|
|
$('#site-content-fill').html('');
|
|
}
|
|
});
|
|
},
|
|
releaseList:function (page) {
|
|
var releaseList = new ReleaseCollection();
|
|
releaseList.fetch({
|
|
success:function () {
|
|
var content = new ReleaseListView({
|
|
collection:releaseList
|
|
}).el;
|
|
$('#content').html(content);
|
|
}
|
|
});
|
|
},
|
|
releaseDetails:function (id) {
|
|
var release = new Release({
|
|
id:id
|
|
});
|
|
$('#site-content-fill').html('');
|
|
release.fetch({
|
|
success:function () {
|
|
var content = new ReleaseView({
|
|
model:release
|
|
}).el;
|
|
$('#content').html(content);
|
|
}
|
|
});
|
|
},
|
|
releaseAdd:function () {
|
|
var html = new ReleaseCreateView({
|
|
model:new Release({
|
|
release_date:com.podnoms.utils.getDateAsToday()
|
|
})
|
|
});
|
|
$('#content').html(html.el);
|
|
$('#site-content-fill').html('');
|
|
},
|
|
releaseEdit:function (id) {
|
|
var release = new Release({
|
|
id:id
|
|
});
|
|
release.fetch({
|
|
success:function () {
|
|
var html = new ReleaseCreateView({
|
|
model:release
|
|
});
|
|
$('#content').html(html.el);
|
|
$('#site-content-fill').html('');
|
|
}
|
|
});
|
|
},
|
|
eventList:function (page) {
|
|
var eventList = new EventCollection();
|
|
eventList.fetch({
|
|
success:function () {
|
|
var content = new EventListView({
|
|
collection:eventList
|
|
}).el;
|
|
$('#content').html(content);
|
|
}
|
|
});
|
|
},
|
|
eventDetails:function (id) {
|
|
var event = new Event({
|
|
id:id
|
|
});
|
|
$('#site-content-fill').html('');
|
|
event.fetch({
|
|
success:function () {
|
|
var content = new EventView({
|
|
model:event
|
|
}).el;
|
|
$('#content').html(content);
|
|
}
|
|
});
|
|
},
|
|
eventAdd:function () {
|
|
var html = new EventCreateView({
|
|
model:new Event({
|
|
event_date:com.podnoms.utils.getDateAsToday()
|
|
})
|
|
});
|
|
$('#content').html(html.el);
|
|
$('#site-content-fill').html('');
|
|
},
|
|
loginRedirect:function () {
|
|
com.podnoms.utils.showAlert("Success", "Thank you for logging in.", "alert-success", true);
|
|
this.defaultRoute();
|
|
},
|
|
login:function () {
|
|
$.colorbox({
|
|
href:"/tpl/LoginView/",
|
|
onClosed:function () {
|
|
Backbone.history.navigate('/', {
|
|
trigger:true
|
|
});
|
|
}
|
|
})
|
|
},
|
|
logout:function () {
|
|
com.podnoms.utils.showAlert("Success", "You are now logged out", "alert-success", true);
|
|
},
|
|
connectAccounts:function () {
|
|
alert("Connecting accounts");
|
|
},
|
|
userDetails:function () {
|
|
var user = new User();
|
|
$('#site-content-fill').html('');
|
|
user.fetch({
|
|
success:function () {
|
|
var content = new UserView({
|
|
model:user
|
|
}).el;
|
|
$('#content').html(content);
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
com.podnoms.utils.loadTemplate(['HeaderView', 'SidebarView', 'UserView', 'MixListView', 'MixListItemView', 'MixView', 'MixCreateView', 'CommentListView', 'CommentListItemView', 'ActivityListView', 'ActivityListItemView', 'ReleaseListView', 'ReleaseListItemView', 'ReleaseItemView', 'ReleaseView', 'ReleaseCreateView', 'ReleaseAudioListView', 'ReleaseAudioItemView', 'EventCreateView', 'EventListView', 'EventListItemView', 'EventView', 'EventItemView'], function () {
|
|
window.app = new AppRouter();
|
|
$(document).on('click', 'a:internal:not(.no-click)', function (event) {
|
|
Backbone.history.navigate($(this).attr('href'), {
|
|
trigger:true
|
|
});
|
|
return false;
|
|
});
|
|
Backbone.history = Backbone.history || new Backbone.History({});
|
|
Backbone.history.start({
|
|
pushState:true
|
|
});
|
|
});
|
|
var _eventAggregator = _.extend({}, Backbone.Events);
|