Section editing interface is now working
This commit is contained in:
14
cms/static/coffee/src/main.coffee
Normal file
14
cms/static/coffee/src/main.coffee
Normal file
@@ -0,0 +1,14 @@
|
||||
@CMS =
|
||||
Models: {}
|
||||
Views: {}
|
||||
|
||||
start: ->
|
||||
new CMS.Views.Course el: $('section.main-container')
|
||||
|
||||
_.extend CMS, Backbone.Events
|
||||
|
||||
$ ->
|
||||
$.ajaxSetup
|
||||
headers : { 'X-CSRFToken': $.cookie 'csrftoken' }
|
||||
|
||||
CMS.start()
|
||||
3
cms/static/coffee/src/models/module.coffee
Normal file
3
cms/static/coffee/src/models/module.coffee
Normal file
@@ -0,0 +1,3 @@
|
||||
class CMS.Models.Module extends Backbone.Model
|
||||
editUrl: ->
|
||||
"/edit_item?id=#{@get('id')}"
|
||||
1
cms/static/coffee/src/models/week.coffee
Normal file
1
cms/static/coffee/src/models/week.coffee
Normal file
@@ -0,0 +1 @@
|
||||
class CMS.Models.Week extends Backbone.Model
|
||||
19
cms/static/coffee/src/views/course.coffee
Normal file
19
cms/static/coffee/src/views/course.coffee
Normal file
@@ -0,0 +1,19 @@
|
||||
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
|
||||
9
cms/static/coffee/src/views/module.coffee
Normal file
9
cms/static/coffee/src/views/module.coffee
Normal file
@@ -0,0 +1,9 @@
|
||||
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))
|
||||
7
cms/static/coffee/src/views/module_edit.coffee
Normal file
7
cms/static/coffee/src/views/module_edit.coffee
Normal file
@@ -0,0 +1,7 @@
|
||||
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()))
|
||||
15
cms/static/coffee/src/views/week.coffee
Normal file
15
cms/static/coffee/src/views/week.coffee
Normal file
@@ -0,0 +1,15 @@
|
||||
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))
|
||||
6
cms/static/coffee/src/views/week_edit.coffee
Normal file
6
cms/static/coffee/src/views/week_edit.coffee
Normal file
@@ -0,0 +1,6 @@
|
||||
class CMS.Views.WeekEdit extends Backbone.View
|
||||
tagName: 'section'
|
||||
className: 'edit-pane'
|
||||
|
||||
initialize: ->
|
||||
CMS.trigger 'week.edit'
|
||||
@@ -7,9 +7,6 @@
|
||||
<%include file="widgets/navigation.html"/>
|
||||
|
||||
<section class="main-content">
|
||||
<section class="edit-pane">
|
||||
<div id="module-html"/>
|
||||
</section>
|
||||
</section>
|
||||
|
||||
</section>
|
||||
|
||||
@@ -34,11 +34,11 @@
|
||||
</ul>
|
||||
</header>
|
||||
|
||||
<ol>
|
||||
<ol id="weeks">
|
||||
% for week in weeks:
|
||||
<li>
|
||||
<li id="${week.location.url()}">
|
||||
<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>
|
||||
% if 'goals' in week.metadata:
|
||||
% for goal in week.metadata['goals']:
|
||||
@@ -50,10 +50,10 @@
|
||||
</ul>
|
||||
</header>
|
||||
|
||||
<ul>
|
||||
<ul id="modules">
|
||||
% for module in week.get_children():
|
||||
<li class="${module.category}">
|
||||
<a href="#" class="module-edit" id="${module.location.url()}">${module.name}</a>
|
||||
<li class="module" data-type="${module.category}" data-id="${module.location.url()}">
|
||||
<a href="#" class="module-edit">${module.name}</a>
|
||||
<a href="#" class="draggable">handle</a>
|
||||
</li>
|
||||
% endfor
|
||||
|
||||
Reference in New Issue
Block a user