Make separate json and xml editing interfaces
This commit is contained in:
@@ -5,6 +5,7 @@ import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class EditingDescriptor(MakoModuleDescriptor):
|
||||
"""
|
||||
Module that provides a raw editing view of its data and children. It does not
|
||||
@@ -14,16 +15,31 @@ class EditingDescriptor(MakoModuleDescriptor):
|
||||
"""
|
||||
mako_template = "widgets/raw-edit.html"
|
||||
|
||||
js = {'coffee': [resource_string(__name__, 'js/src/raw/edit.coffee')]}
|
||||
js_module_name = "RawDescriptor"
|
||||
|
||||
|
||||
# cdodge: a little refactoring here, since we're basically doing the same thing
|
||||
# here as with our parent class, let's call into it to get the basic fields
|
||||
# set and then add our additional fields. Trying to keep it DRY.
|
||||
def get_context(self):
|
||||
_context = MakoModuleDescriptor.get_context(self)
|
||||
# Add our specific template information (the raw data body)
|
||||
_context.update({ 'data' : self.definition.get('data','') })
|
||||
_context.update({'data': self.definition.get('data', '')})
|
||||
return _context
|
||||
|
||||
|
||||
|
||||
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
|
||||
|
||||
from lxml import etree
|
||||
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
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ class NonStaffErrorModule(XModule):
|
||||
})
|
||||
|
||||
|
||||
class ErrorDescriptor(EditingDescriptor):
|
||||
class ErrorDescriptor(JSONEditingDescriptor):
|
||||
"""
|
||||
Module that provides a raw editing view of broken xml.
|
||||
"""
|
||||
|
||||
@@ -1,5 +0,0 @@
|
||||
class @RawDescriptor
|
||||
constructor: (@element) ->
|
||||
@edit_box = $(".edit-box", @element)
|
||||
|
||||
save: -> @edit_box.val()
|
||||
7
common/lib/xmodule/xmodule/js/src/raw/edit/json.coffee
Normal file
7
common/lib/xmodule/xmodule/js/src/raw/edit/json.coffee
Normal file
@@ -0,0 +1,7 @@
|
||||
class @JSONEditingDescriptor
|
||||
constructor: (@element) ->
|
||||
@edit_box = CodeMirror.fromTextArea($(".edit-box", @element)[0], {
|
||||
mode: { name: "javascript", json: true }
|
||||
})
|
||||
|
||||
save: -> JSON.parse @edit_box.getValue()
|
||||
7
common/lib/xmodule/xmodule/js/src/raw/edit/xml.coffee
Normal file
7
common/lib/xmodule/xmodule/js/src/raw/edit/xml.coffee
Normal file
@@ -0,0 +1,7 @@
|
||||
class @XMLEditingDescriptor
|
||||
constructor: (@element) ->
|
||||
@edit_box = CodeMirror.fromTextArea($(".edit-box", @element)[0], {
|
||||
mode: "xml"
|
||||
})
|
||||
|
||||
save: -> @edit_box.getValue()
|
||||
@@ -1,19 +1,19 @@
|
||||
from lxml import etree
|
||||
from xmodule.editing_module import EditingDescriptor
|
||||
from xmodule.editing_module import XMLEditingDescriptor
|
||||
from xmodule.xml_module import XmlDescriptor
|
||||
import logging
|
||||
import sys
|
||||
|
||||
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
|
||||
requires that the definition xml is valid.
|
||||
"""
|
||||
@classmethod
|
||||
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):
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user