1 /*global View render_template panels */
2 var HTMLView = View.extend({
3 _className: 'HTMLView',
6 template: 'html-view-template',
8 init: function(element, model, parent, template) {
9 this._super(element, model, template);
13 .addObserver(this, 'data', this.modelDataChanged.bind(this))
14 .addObserver(this, 'state', this.modelStateChanged.bind(this));
16 $('.htmlview', this.element).html(this.model.get('data'));
17 this.modelStateChanged('state', this.model.get('state'));
21 modelDataChanged: function(property, value) {
22 $('.htmlview', this.element).html(value);
23 this.updatePrintLink();
26 updatePrintLink: function() {
27 var base = this.$printLink.attr('ui:baseref');
28 this.$printLink.attr('href', base + "?user="+this.model.document.get('user')+"&revision=" + this.model.get('revision'));
31 modelStateChanged: function(property, value)
35 if (value == 'synced' || value == 'dirty') {
37 } else if (value == 'unsynced') {
38 this.freeze('Niezsynchronizowany...');
39 } else if (value == 'loading') {
40 this.freeze('Ćadowanie...');
41 } else if (value == 'saving') {
42 this.freeze('Zapisywanie...');
43 } else if (value == 'error') {
44 this.freeze(this.model.get('error'));
45 $('.xml-editor-ref', this.overlay).click(
47 console.log("Sending scroll rq.", this);
49 var href = $(this).attr('href').split('-');
50 var line = parseInt(href[1]);
51 var column = parseInt(href[2]);
53 $(document).trigger('xml-scroll-request', {line:line, column:column});
64 this.element.unbind('click');
66 if(this.$printLink) this.$printLink.unbind();
68 this.$printLink = $('.html-print-link', this.element);
69 this.updatePrintLink();
71 this.element.bind('click', this.itemClicked.bind(this));
75 this.model.load(true);
79 this.model.removeObserver(this);
83 itemClicked: function(event)
87 console.log('click:', event, event.ctrlKey, event.target);
88 var editableContent = null;
89 var $e = $(event.target);
93 while( ($e[0] != this.element[0]) && !($e.attr('wl2o:editable'))
96 // console.log($e, $e.parent(), this.element);
101 if(!$e.attr('wl2o:editable'))
104 // start edition on this node
108 '<div class="html-editarea">\n\
109 <p class="html-editarea-toolbar">\n\
110 <button class="html-editarea-save-button" type="button">Zapisz</button>\n\
111 <button class="html-editarea-cancel-button" type="button">Anuluj</button>\n\
113 <textarea></textarea>\n\
116 var x = $e[0].offsetLeft;
117 var y = $e[0].offsetTop;
118 var w = $e.outerWidth();
119 var h = $e.innerHeight();
120 $overlay.css({position: 'absolute', height: h, left: "5%", top: y, width: "90%"});
121 $e.offsetParent().append($overlay);
123 // load the original XML content
124 console.log($e, $e.offsetParent(), $overlay);
126 $('.html-editarea-cancel-button', $overlay).click(function() {
130 $('.html-editarea-save-button', $overlay).click(function() {
133 // put the part back to the model
134 self.model.putXMLPart($e, $('textarea', $overlay).val());
137 $('textarea', $overlay).focus(function() {
138 $overlay.css('z-index', 3000);
140 $overlay.css('z-index', 2000);
143 this.model.getXMLPart($e, function(path, data) {
144 $('textarea', $overlay).val(data);
153 panels['html'] = HTMLView;