Commit a7dc045f by Prem Sichanugrist

External module loading

parent 7c044aa1
class CMS.Models.Module extends Backbone.Model class CMS.Models.Module extends Backbone.Model
initialize: ->
try
@module = new window[@get('type')](@get('id'))
catch TypeError
console.error "Unable to load #{@get('type')}." if console
editUrl: -> editUrl: ->
"/edit_item?id=#{@get('id')}" "/edit_item?#{$.param(id: @get('id'))}"
...@@ -3,7 +3,7 @@ class CMS.Views.Module extends Backbone.View ...@@ -3,7 +3,7 @@ class CMS.Views.Module extends Backbone.View
"click .module-edit": "edit" "click .module-edit": "edit"
initialize: -> initialize: ->
@model = new CMS.Models.Module(id: @el.id) @model = new CMS.Models.Module(id: @$el.data('id'), type: @$el.data('type'))
edit: => edit: =>
CMS.trigger('showContent', new CMS.Views.ModuleEdit(model: @model)) CMS.trigger('showContent', new CMS.Views.ModuleEdit(model: @model))
...@@ -3,4 +3,4 @@ class CMS.Views.WeekEdit extends Backbone.View ...@@ -3,4 +3,4 @@ class CMS.Views.WeekEdit extends Backbone.View
className: 'edit-pane' className: 'edit-pane'
initialize: -> initialize: ->
CMS.trigger 'week.edit' CMS.trigger('week.edit')
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
<ol id="weeks"> <ol id="weeks">
% for week in weeks: % for week in weeks:
<li id="${week.location.url()}"> <li class="week" data-id="${week.location.url()}">
<header> <header>
<h1><a href="#" class="module-edit">${week.name}</a></h1> <h1><a href="#" class="module-edit">${week.name}</a></h1>
<ul> <ul>
...@@ -50,9 +50,9 @@ ...@@ -50,9 +50,9 @@
</ul> </ul>
</header> </header>
<ul id="modules"> <ul class="modules">
% for module in week.get_children(): % for module in week.get_children():
<li class="module" data-type="${module.category}" data-id="${module.location.url()}"> <li class="module" data-id="${module.location.url()}" data-type="${module.category}">
<a href="#" class="module-edit">${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>
......
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