Commit 5f237ab3 by Calen Pennington

Make separate json and xml editing interfaces

parent 344ec952
...@@ -14,9 +14,6 @@ class EditingDescriptor(MakoModuleDescriptor): ...@@ -14,9 +14,6 @@ class EditingDescriptor(MakoModuleDescriptor):
""" """
mako_template = "widgets/raw-edit.html" mako_template = "widgets/raw-edit.html"
js = {'coffee': [resource_string(__name__, 'js/src/raw/edit.coffee')]}
js_module_name = "RawDescriptor"
def get_context(self): def get_context(self):
return { return {
'module': self, 'module': self,
...@@ -27,3 +24,23 @@ class EditingDescriptor(MakoModuleDescriptor): ...@@ -27,3 +24,23 @@ class EditingDescriptor(MakoModuleDescriptor):
# TODO: show both own metadata and inherited? # TODO: show both own metadata and inherited?
#'metadata' : self.own_metadata, #'metadata' : self.own_metadata,
} }
class XMLEditingDescriptor(EditingDescriptor):
"""
Module that provides a raw editing view of its data as XML. It does not perform
any validation of its definition
"""
js = {'coffee': [resource_string(__name__, 'js/src/raw/edit/xml.coffee')]}
js_module_name = "XMLEditingDescriptor"
class JSONEditingDescriptor(EditingDescriptor):
"""
Module that provides a raw editing view of its data as XML. It does not perform
any validation of its definition
"""
js = {'coffee': [resource_string(__name__, 'js/src/raw/edit/json.coffee')]}
js_module_name = "JSONEditingDescriptor"
...@@ -5,7 +5,7 @@ import sys ...@@ -5,7 +5,7 @@ import sys
from lxml import etree from lxml import etree
from xmodule.x_module import XModule from xmodule.x_module import XModule
from xmodule.editing_module import EditingDescriptor from xmodule.editing_module import JSONEditingDescriptor
from xmodule.errortracker import exc_info_to_str from xmodule.errortracker import exc_info_to_str
...@@ -45,7 +45,7 @@ class NonStaffErrorModule(XModule): ...@@ -45,7 +45,7 @@ class NonStaffErrorModule(XModule):
}) })
class ErrorDescriptor(EditingDescriptor): class ErrorDescriptor(JSONEditingDescriptor):
""" """
Module that provides a raw editing view of broken xml. Module that provides a raw editing view of broken xml.
""" """
......
class @RawDescriptor
constructor: (@element) ->
@edit_box = $(".edit-box", @element)
save: -> @edit_box.val()
class @JSONEditingDescriptor
constructor: (@element) ->
@edit_box = CodeMirror.fromTextArea($(".edit-box", @element)[0], {
mode: { name: "javascript", json: true }
})
save: -> JSON.parse @edit_box.getValue()
class @XMLEditingDescriptor
constructor: (@element) ->
@edit_box = CodeMirror.fromTextArea($(".edit-box", @element)[0], {
mode: "xml"
})
save: -> @edit_box.getValue()
from lxml import etree from lxml import etree
from xmodule.editing_module import EditingDescriptor from xmodule.editing_module import XMLEditingDescriptor
from xmodule.xml_module import XmlDescriptor from xmodule.xml_module import XmlDescriptor
import logging import logging
import sys import sys
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
class RawDescriptor(XmlDescriptor, EditingDescriptor): class RawDescriptor(XmlDescriptor, XMLEditingDescriptor):
""" """
Module that provides a raw editing view of its data and children. It Module that provides a raw editing view of its data and children. It
requires that the definition xml is valid. requires that the definition xml is valid.
""" """
@classmethod @classmethod
def definition_from_xml(cls, xml_object, system): def definition_from_xml(cls, xml_object, system):
return {'data': etree.tostring(xml_object)} return {'data': etree.tostring(xml_object, pretty_print=True)}
def definition_to_xml(self, resource_fs): def definition_to_xml(self, resource_fs):
try: try:
......
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