2015-04-15 01:36:42 +00:00
|
|
|
define([
|
|
|
|
'jquery',
|
|
|
|
'underscore',
|
|
|
|
'backbone',
|
|
|
|
'common'
|
|
|
|
], function($, _, Backbone, Common) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var MyhomeSideNavView = Backbone.View.extend({
|
|
|
|
el: '#myhome-side-nav',
|
|
|
|
|
|
|
|
template: _.template($("#myhome-side-nav-tmpl").html()),
|
|
|
|
enableModTemplate: _.template($("#myhome-mods-enable-form-tmpl").html()),
|
|
|
|
|
|
|
|
initialize: function() {
|
2015-07-22 03:59:50 +00:00
|
|
|
this.default_cur_tab = 'libs';
|
|
|
|
this.data = {
|
|
|
|
'cur_tab': this.default_cur_tab,
|
2015-04-15 01:36:42 +00:00
|
|
|
'mods_enabled': app.pageOptions.user_mods_enabled,
|
2015-04-16 03:58:13 +00:00
|
|
|
'can_add_repo': app.pageOptions.can_add_repo,
|
2015-04-15 01:36:42 +00:00
|
|
|
'events_enabled': app.pageOptions.events_enabled
|
2015-07-22 03:59:50 +00:00
|
|
|
};
|
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
this.$el.html(this.template(this.data));
|
2015-05-04 09:02:20 +00:00
|
|
|
return this;
|
2015-04-15 01:36:42 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
events: {
|
|
|
|
'click #myhome-enable-mods': 'enableMods'
|
|
|
|
},
|
|
|
|
|
|
|
|
enableMods: function () {
|
2015-04-16 03:58:13 +00:00
|
|
|
var mods_enabled = app.pageOptions.user_mods_enabled;
|
2015-04-15 01:36:42 +00:00
|
|
|
var form = $(this.enableModTemplate({
|
|
|
|
'mods_available': app.pageOptions.user_mods_available,
|
2015-04-16 03:58:13 +00:00
|
|
|
'mods_enabled': mods_enabled
|
2015-04-15 01:36:42 +00:00
|
|
|
}));
|
|
|
|
form.modal();
|
|
|
|
$('#simplemodal-container').css('height', 'auto');
|
|
|
|
|
|
|
|
$('.checkbox-orig', form).click(function() {
|
|
|
|
$(this).parent().toggleClass('checkbox-checked');
|
|
|
|
});
|
|
|
|
|
|
|
|
var checkbox = $('[name="personal_wiki"]'),
|
|
|
|
original_checked = checkbox.prop('checked'),
|
|
|
|
_this = this;
|
|
|
|
form.submit(function() {
|
|
|
|
var cur_checked = checkbox.prop('checked');
|
|
|
|
if (cur_checked == original_checked) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Common.ajaxPost({
|
|
|
|
form: form,
|
|
|
|
form_id: form.attr('id'),
|
|
|
|
post_url: Common.getUrl({
|
2015-04-16 03:58:13 +00:00
|
|
|
'name': 'toggle_personal_modules'
|
2015-04-15 01:36:42 +00:00
|
|
|
}),
|
|
|
|
post_data: {'personal_wiki': cur_checked },
|
|
|
|
after_op_success: function () {
|
|
|
|
if (cur_checked) {
|
2015-04-16 03:58:13 +00:00
|
|
|
mods_enabled.push('personal wiki');
|
2015-04-15 01:36:42 +00:00
|
|
|
} else {
|
2015-04-16 03:58:13 +00:00
|
|
|
var index = mods_enabled.indexOf('personal wiki');
|
2015-04-15 01:36:42 +00:00
|
|
|
if (index > -1) {
|
2015-04-16 03:58:13 +00:00
|
|
|
mods_enabled.splice(index, 1); // rm the item
|
2015-04-15 01:36:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
$.modal.close();
|
|
|
|
_this.render();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2015-07-22 03:59:50 +00:00
|
|
|
show: function(options) {
|
|
|
|
if (options && options.cur_tab) {
|
|
|
|
this.data.cur_tab = options.cur_tab;
|
|
|
|
this.render();
|
|
|
|
} else {
|
|
|
|
if (this.data.cur_tab != this.default_cur_tab) {
|
|
|
|
this.data.cur_tab = this.default_cur_tab;
|
|
|
|
this.render();
|
|
|
|
}
|
|
|
|
}
|
2015-04-15 01:36:42 +00:00
|
|
|
this.$el.show();
|
|
|
|
},
|
|
|
|
|
|
|
|
hide: function() {
|
|
|
|
this.$el.hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return MyhomeSideNavView;
|
|
|
|
});
|