Commit 335c6949 by Tom Giannattasio

started consolidating editor functions

parent 5dd90aa9
<li> <li name="<%- updateModel.cid %>">
<!-- FIXME what style should we use for initially hidden? --> <!-- TODO decide whether this should use codemirror --> <!-- FIXME what style should we use for initially hidden? --> <!-- TODO decide whether this should use codemirror -->
<form class="new-update-form"> <form class="new-update-form">
<div class="row"> <div class="row">
<label class="inline-label">Date:</label> <label class="inline-label">Date:</label>
<!-- TODO replace w/ date widget and actual date (problem is that persisted version is "Month day" not an actual date obj --> <!-- TODO replace w/ date widget and actual date (problem is that persisted version is "Month day" not an actual date obj -->
<input type="text" class="date" id="date-entry" value="<%= updateModel.get('date') %>"> <input type="text" class="date" value="<%= updateModel.get('date') %>">
</div> </div>
<div class="row"> <div class="row">
<textarea class="new-update-content text-editor"><%= updateModel.get('content') %></textarea> <textarea class="new-update-content text-editor"><%= updateModel.get('content') %></textarea>
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
<a href="#" class="delete-button" name="<%- updateModel.cid %>"><span class="delete-icon"></span>Delete</a> <a href="#" class="delete-button" name="<%- updateModel.cid %>"><span class="delete-icon"></span>Delete</a>
</div> </div>
<h2> <h2>
<span class="calendar-icon"></span><span id="date-display"><%= <span class="calendar-icon"></span><span class="date-display"><%=
updateModel.get('date') %></span> updateModel.get('date') %></span>
</h2> </h2>
<div class="update-contents"><%= updateModel.get('content') %></div> <div class="update-contents"><%= updateModel.get('content') %></div>
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
if (typeof window.templateLoader == 'function') return; if (typeof window.templateLoader == 'function') return;
var templateLoader = { var templateLoader = {
templateVersion: "0.0.3", templateVersion: "0.0.4",
templates: {}, templates: {},
loadRemoteTemplate: function(templateName, filename, callback) { loadRemoteTemplate: function(templateName, filename, callback) {
if (!this.templates[templateName]) { if (!this.templates[templateName]) {
......
...@@ -53,36 +53,35 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -53,36 +53,35 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
$(updateEle).append(newEle); $(updateEle).append(newEle);
}); });
this.$el.find(".new-update-form").hide(); this.$el.find(".new-update-form").hide();
this.$el.find('.date').datepicker({ 'dateFormat': 'MM d' }); this.$el.find('.date').datepicker({ 'dateFormat': 'MM d, yy' });
return this; return this;
}, },
onNew: function(event) { onNew: function(event) {
var self = this;
// create new obj, insert into collection, and render this one ele overriding the hidden attr // create new obj, insert into collection, and render this one ele overriding the hidden attr
var newModel = new CMS.Models.CourseUpdate(); var newModel = new CMS.Models.CourseUpdate();
this.collection.add(newModel, {at : 0}); this.collection.add(newModel, {at : 0});
var newForm = this.template({ updateModel : newModel }); var $newForm = $(this.template({ updateModel : newModel }));
var updateEle = this.$el.find("#course-update-list"); var updateEle = this.$el.find("#course-update-list");
$(updateEle).prepend(newForm); $(updateEle).prepend($newForm);
$newForm.addClass('editing');
// TODO: remove the id on the datepicker field
// this is causing conflicts with the datepicker widget
$modalCover.show();
$modalCover.bind('click', function() {
self.closeEditor(self);
});
$('.date').datepicker('destroy'); $('.date').datepicker('destroy');
$('.date').datepicker({ 'dateFormat': 'MM d' }); $('.date').datepicker({ 'dateFormat': 'MM d, yy' });
}, },
onSave: function(event) { onSave: function(event) {
var targetModel = this.eventModel(event); var targetModel = this.eventModel(event);
targetModel.set({ date : this.dateEntry(event).val(), content : this.contentEntry(event).val() }); targetModel.set({ date : this.dateEntry(event).val(), content : this.contentEntry(event).val() });
// push change to display, hide the editor, submit the change // push change to display, hide the editor, submit the change
$(this.dateDisplay(event)).html(targetModel.get('date')); this.closeEditor(this);
$(this.contentDisplay(event)).html(targetModel.get('content'));
$(this.editor(event)).hide();
targetModel.save(); targetModel.save();
}, },
...@@ -90,12 +89,19 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -90,12 +89,19 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
// change editor contents back to model values and hide the editor // change editor contents back to model values and hide the editor
$(this.editor(event)).hide(); $(this.editor(event)).hide();
var targetModel = this.eventModel(event); var targetModel = this.eventModel(event);
$(this.dateEntry(event)).html(targetModel.get('date')); this.closeEditor(this);
$(this.contentEntry(event)).html(targetModel.get('content'));
}, },
onEdit: function(event) { onEdit: function(event) {
var self = this;
this.$currentPost = $(event.target).closest('li');
this.$currentPost.addClass('editing');
$(this.editor(event)).slideDown(150); $(this.editor(event)).slideDown(150);
$modalCover.show();
var targetModel = this.eventModel(event);
$modalCover.bind('click', function() {
self.closeEditor(self);
});
}, },
onDelete: function(event) { onDelete: function(event) {
...@@ -110,6 +116,16 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -110,6 +116,16 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
}); });
}, },
closeEditor: function(self) {
var targetModel = self.collection.getByCid(self.$currentPost.attr('name'));
self.$currentPost.removeClass('editing');
self.$currentPost.find('.date-display').html(targetModel.get('date'));
self.$currentPost.find('.update-contents').html(targetModel.get('content'));
self.$currentPost.find('form').hide();
$modalCover.hide();
},
// Dereferencing from events to screen elements // Dereferencing from events to screen elements
eventModel: function(event) { eventModel: function(event) {
// not sure if it should be currentTarget or delegateTarget // not sure if it should be currentTarget or delegateTarget
...@@ -127,7 +143,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({ ...@@ -127,7 +143,7 @@ CMS.Views.ClassInfoUpdateView = Backbone.View.extend({
dateEntry: function(event) { dateEntry: function(event) {
var li = $(event.currentTarget).closest("li"); var li = $(event.currentTarget).closest("li");
if (li) return $(li).find("#date-entry").first(); if (li) return $(li).find(".date").first();
}, },
contentEntry: function(event) { contentEntry: function(event) {
......
...@@ -4,6 +4,19 @@ ...@@ -4,6 +4,19 @@
li { li {
padding: 34px 0 42px; padding: 34px 0 42px;
border-top: 1px solid #cbd1db; border-top: 1px solid #cbd1db;
&.editing {
position: relative;
z-index: 1001;
padding: 0;
border-top: none;
border-radius: 3px;
background: #fff;
.post-preview {
display: none;
}
}
} }
h2 { h2 {
...@@ -44,6 +57,7 @@ ...@@ -44,6 +57,7 @@
.new-update-form { .new-update-form {
@include edit-box; @include edit-box;
margin-bottom: 24px; margin-bottom: 24px;
border: none;
textarea { textarea {
height: 180px; height: 180px;
......
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