Commit b46f6a6d by Prem Sichanugrist

Section editing interface is now working

parent 0e87ada0
@CMS =
Models: {}
Views: {}
start: ->
new CMS.Views.Course el: $('section.main-container')
_.extend CMS, Backbone.Events
$ ->
$.ajaxSetup
headers : { 'X-CSRFToken': $.cookie 'csrftoken' }
CMS.start()
class CMS.Models.Module extends Backbone.Model
editUrl: ->
"/edit_item?id=#{@get('id')}"
class CMS.Models.Week extends Backbone.Model
class CMS.Views.Course extends Backbone.View
initialize: ->
@$('#weeks > li').each (index, week) =>
new CMS.Views.Week el: week, height: @maxWeekHeight()
CMS.on('showContent', @showContent)
showContent: (subview) =>
$('body').addClass('content')
@$('.main-content').html(subview.el)
@$('.cal').css height: @contentHeight()
@$('>section').css minHeight: @contentHeight()
maxWeekHeight: ->
_.max($('#weeks > li').map -> $(this).height()) + 1
contentHeight: ->
padding = 29
$(window).height() - padding
class CMS.Views.Module extends Backbone.View
events:
"click .module-edit": "edit"
initialize: ->
@model = new CMS.Models.Module(id: @el.id)
edit: =>
CMS.trigger('showContent', new CMS.Views.ModuleEdit(model: @model))
class CMS.Views.ModuleEdit extends Backbone.View
tagName: 'section'
className: 'edit-pane'
initialize: ->
CMS.trigger 'module.edit'
@$el.append($('<div id="module-html">').load(@model.editUrl()))
class CMS.Views.Week extends Backbone.View
events:
'click .module-edit': 'edit'
initialize: ->
@model = new CMS.Models.Week(id: @el.id)
@$el.height @options.height
@$('.editable').inlineEdit()
@$('.editable-textarea').inlineEdit(control: 'textarea')
@$('#modules .module').each ->
new CMS.Views.Module el: this
edit: =>
CMS.trigger('showContent', new CMS.Views.WeekEdit(model: @model))
class CMS.Views.WeekEdit extends Backbone.View
tagName: 'section'
className: 'edit-pane'
initialize: ->
CMS.trigger 'week.edit'
...@@ -7,9 +7,6 @@ ...@@ -7,9 +7,6 @@
<%include file="widgets/navigation.html"/> <%include file="widgets/navigation.html"/>
<section class="main-content"> <section class="main-content">
<section class="edit-pane">
<div id="module-html"/>
</section>
</section> </section>
</section> </section>
......
...@@ -34,11 +34,11 @@ ...@@ -34,11 +34,11 @@
</ul> </ul>
</header> </header>
<ol> <ol id="weeks">
% for week in weeks: % for week in weeks:
<li> <li id="${week.location.url()}">
<header> <header>
<h1><a href="#" class="module-edit" id="${week.location.url()}">${week.name}</a></h1> <h1><a href="#" class="module-edit">${week.name}</a></h1>
<ul> <ul>
% if 'goals' in week.metadata: % if 'goals' in week.metadata:
% for goal in week.metadata['goals']: % for goal in week.metadata['goals']:
...@@ -50,10 +50,10 @@ ...@@ -50,10 +50,10 @@
</ul> </ul>
</header> </header>
<ul> <ul id="modules">
% for module in week.get_children(): % for module in week.get_children():
<li class="${module.category}"> <li class="module" data-type="${module.category}" data-id="${module.location.url()}">
<a href="#" class="module-edit" id="${module.location.url()}">${module.name}</a> <a href="#" class="module-edit">${module.name}</a>
<a href="#" class="draggable">handle</a> <a href="#" class="draggable">handle</a>
</li> </li>
% endfor % endfor
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment