+ CodeMirror.fromTextArea('id_text', {
+ parserfile: 'parsexml.js',
+ path: STATIC_URL + "js/lib/codemirror/",
+ stylesheet: STATIC_URL + "css/xmlcolors.css",
+ parserConfig: {
+ useHTMLKludges: false
+ },
+ iframeClass: 'xml-iframe',
+ textWrapping: true,
+ tabMode: 'spaces',
+ indentUnit: 0,
+ initCallback: function(editor) {
+ $('#save-button').click(function(event) {
+ event.preventDefault();
+ $.blockUI({message: $('#save-dialog')});
+ });
+
+ $('#save-ok').click(function() {
+ $.blockUI({message: 'Zapisywanie...'});
+
+ function doSave (argument) {
+ var metaComment = '<!--';
+ $('#document-meta div').each(function() {
+ metaComment += '\n\t' + $(this).attr('class') + ': ' + $(this).html();
+ });
+ metaComment += '\n-->'
+
+ var data = {
+ name: $('#document-name').html(),
+ text: metaComment + editor.getCode(),
+ revision: $('#document-revision').html(),
+ author: 'annonymous',
+ comment: $('#komentarz').val()
+ };
+
+ console.log(data);
+
+ $.ajax({
+ url: document.location.href,
+ type: "POST",
+ dataType: "json",
+ data: data,
+ success: function(data) {
+ if (data.text) {
+ editor.setCode(data.text);
+ $('#document-revision').html(data.revision);
+ } else {
+ console.log(data.errors);
+ alert(data.errors);
+ }
+ $.unblockUI();
+ },
+ error: function(xhr, textStatus, errorThrown) {
+ alert('error: ' + textStatus + ' ' + errorThrown);
+ },
+ })
+ }
+
+ if ('#simple-view-tab.active') {
+ reverseTransform(editor, doSave);
+ } else {
+ doSave();
+ }
+ });
+
+ $('#save-cancel').click(function() {
+ $.unblockUI();
+ });
+
+ $('#simple-view-tab').click(function() {
+ if ($(this).hasClass('active')) {
+ return;
+ }
+ $(this).addClass('active');
+ $('#source-view-tab').removeClass('active');
+ $('#source-editor').hide();
+ $('#simple-editor').show();
+ transform(editor);
+ });
+
+ $('#source-view-tab').click(function() {
+ if ($(this).hasClass('active')) {
+ return;
+ }
+ $(this).addClass('active');
+ $('#simple-view-tab').removeClass('active');
+ $('#simple-editor').hide();
+ $('#source-editor').show();
+ reverseTransform(editor);
+ });
+
+ $('#source-editor .toolbar button').click(function(event) {
+ event.preventDefault();
+ var params = eval("(" + $(this).attr('ui:action-params') + ")");
+ scriptletCenter.scriptlets[$(this).attr('ui:action')](editor, params);
+ });
+
+ $('.toolbar select').change(function() {
+ var slug = $(this).val();
+
+ $('.toolbar-buttons-container').hide().filter('[data-group=' + slug + ']').show();
+ $(window).resize();
+ });
+
+ $('.toolbar-buttons-container').hide();
+ $('.toolbar select').change();
+
+ $('#simple-view-tab').click();
+ }
+ });
+
+ $(window).resize(function() {
+ $('iframe').height($(window).height() - $('#tabs').outerHeight() - $('#source-editor .toolbar').outerHeight());