\r
.rng-tab-content {\r
display: none;\r
+}\r
+\r
+#rng-skelton-menu {\r
+ float: right;\r
+}\r
+\r
+#rng-skelton-menu ul {\r
+ list-style-type: none;\r
}
\ No newline at end of file
rng.modules.data = function(sandbox) {\r
\r
- var document = sandbox.getBootstrappedData().document;\r
+ var doc = sandbox.getBootstrappedData().document;\r
+ var document_id = sandbox.getBootstrappedData().document_id;\r
\r
+ function readCookie(name) {\r
+ var nameEQ = escape(name) + "=";\r
+ var ca = document.cookie.split(';');\r
+ for (var i = 0; i < ca.length; i++) {\r
+ var c = ca[i];\r
+ while (c.charAt(0) == ' ') c = c.substring(1, c.length);\r
+ if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length));\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ $.ajaxSetup({\r
+ crossDomain: false,\r
+ beforeSend: function(xhr, settings) {\r
+ if (!(/^(GET|HEAD|OPTIONS|TRACE)$/.test(settings.type))) {\r
+ xhr.setRequestHeader("X-CSRFToken", readCookie('csrftoken'));\r
+ }\r
+ }\r
+ });\r
+ \r
return {\r
start: function() {\r
sandbox.publish('ready');\r
},\r
getDocument: function() {\r
- return document;\r
+ return doc;\r
},\r
commitDocument: function(newDocument, reason) {\r
- document = newDocument;\r
- sandbox.publish('documentChanged', document, reason);\r
+ doc = newDocument;\r
+ sandbox.publish('documentChanged', doc, reason);\r
+ },\r
+ saveDocument: function() {\r
+ $.ajax({\r
+ method: 'post',\r
+ url: '/editor/' + document_id,\r
+ data: JSON.stringify({document:doc})\r
+ });\r
}\r
\r
}\r
eventHandlers.skelton = {\r
ready: function() {\r
sandbox.getModule('tabsManager').start();\r
+ },\r
+ 'cmd.save': function() {\r
+ var editorSlugs = ['visual', 'source'];\r
+ var slug = sandbox.getModule('tabsManager').getCurrentSlug();\r
+ if(_.contains(editorSlugs, slug)) {\r
+ var editor = sandbox.getModule(slug+'Editor');\r
+ if(editor.isDirty()) {\r
+ sandbox.getModule('data').commitDocument(editor.getDocument(), slug + '_edit');\r
+ editor.setDirty(false);\r
+ }\r
+ }\r
+ sandbox.getModule('data').saveDocument();\r
}\r
};\r
\r
rng.modules.skelton = function(sandbox) {\r
+ \r
+ var view = $(sandbox.getTemplate('main')());\r
+ \r
+ view.find('#rng-skelton-menu a').click(function(e) {\r
+ e.preventDefault();\r
+ sandbox.publish('cmd.' + $(e.target).attr('data-cmd'));\r
+ });\r
+ \r
return {\r
start: function() {\r
+ sandbox.getDOM().append(view);\r
sandbox.publish('ready');\r
},\r
- setMainView: function(view) {\r
- sandbox.getDOM().html(view);\r
+ setMainView: function(mainView) {\r
+ view.find('#rng-skelton-mainView').html(mainView);\r
}\r
}\r
};
\ No newline at end of file
var $ = sandbox.$;\r
\r
var view = $(sandbox.getTemplate('main')());\r
- \r
+ var currentSlug;\r
var tabContent = {};\r
\r
function selectTab(slug) {\r
if(prevSlug)\r
tabContent[prevSlug].detach();\r
tabContent[slug].appendTo(view.find('#rng-tabsManager-content'));\r
+ currentSlug = slug;\r
}\r
\r
\r
view.find('#rng-tabsManager-tabBar').append(sandbox.getTemplate('tabHandle')({title: title, slug: slug}));\r
if(_.values(tabContent).length === 1)\r
selectTab(slug);\r
+ },\r
+ getCurrentSlug: function() {\r
+ return currentSlug;\r
}\r
}\r
\r