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             documentIsDirty = false;
 
  22     view.onHide = function() {
 
  23         if(documentEditedHere) {
 
  28     var commitDocument = function() {
 
  29         documentEditedHere = false;
 
  30         wlxmlDocument.loadXML(editor.getValue());
 
  34     var editor = ace.edit(view.find('#rng-sourceEditor-editor')[0]),
 
  35         session = editor.getSession();
 
  36     editor.setTheme('ace/theme/chrome');
 
  37     session.setMode('ace/mode/xml');
 
  38     session.setUseWrapMode(true);
 
  40     editor.getSession().on('change', function() {
 
  41         documentEditedHere = true;
 
  45             sandbox.publish('ready');
 
  50         setDocument: function(document) {
 
  51             wlxmlDocument = document;
 
  52             wlxmlDocument.on('change', function() {
 
  53                 documentIsDirty = true;
 
  55             wlxmlDocument.on('contentSet', function() {
 
  56                 documentIsDirty = true;
 
  59         changesCommited: function() {
 
  60             return !documentEditedHere;
 
  62         commitChanges: commitDocument,
 
  63         getDocument: function() {
 
  64             return editor.getValue();