1 define(['libs/jquery', 'libs/text!./template.html'], function($, template) {
5 return function(sandbox) {
7 var view = $(template),
8 documentIsDirty = true,
9 documentEditedHere = false,
12 view.onShow = function() {
14 editor.setValue(wlxmlDocument.toXML());
16 documentEditedHere = false;
18 sandbox.publish('documentSet');
19 documentIsDirty = false;
23 view.onHide = function() {
24 if(documentEditedHere) {
29 var commitDocument = function() {
30 documentEditedHere = false;
31 wlxmlDocument.loadXML(editor.getValue());
35 var editor = ace.edit(view.find('#rng-sourceEditor-editor')[0]),
36 session = editor.getSession();
37 editor.setTheme('ace/theme/chrome');
38 session.setMode('ace/mode/xml');
39 session.setUseWrapMode(true);
41 editor.getSession().on('change', function() {
42 documentEditedHere = true;
46 sandbox.publish('ready');
51 setDocument: function(document) {
52 wlxmlDocument = document;
53 wlxmlDocument.on('change', function() {
54 documentIsDirty = true;
56 wlxmlDocument.on('contentSet', function() {
57 documentIsDirty = true;
60 changesCommited: function() {
61 return !documentEditedHere;
63 commitChanges: commitDocument,
64 getDocument: function() {
65 return editor.getValue();