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);
24 var base = this.$printLink.attr('ui:baseref');
25 this.$printLink.attr('href', base + "?revision=" + this.model.get('revision'));
28 modelStateChanged: function(property, value)
32 if (value == 'synced' || value == 'dirty') {
34 } else if (value == 'unsynced') {
35 this.freeze('Niezsynchronizowany...');
36 } else if (value == 'loading') {
37 this.freeze('Ćadowanie...');
38 } else if (value == 'saving') {
39 this.freeze('Zapisywanie...');
40 } else if (value == 'error') {
41 this.freeze(this.model.get('error'));
42 $('.xml-editor-ref', this.overlay).click(
44 console.log("Sending scroll rq.", this);
46 var href = $(this).attr('href').split('-');
47 var line = parseInt(href[1]);
48 var column = parseInt(href[2]);
50 $(document).trigger('xml-scroll-request', {line:line, column:column});
61 this.element.unbind('click');
63 if(this.$printLink) this.$printLink.unbind();
65 this.$printLink = $('.html-print-link', this.element);
67 var base = this.$printLink.attr('ui:baseref');
68 this.$printLink.attr('href', base + "?revision=" + this.model.get('revision'));
70 this.element.bind('click', this.itemClicked.bind(this));
74 this.model.load(true);
78 this.model.removeObserver(this);
82 itemClicked: function(event)
86 console.log('click:', event, event.ctrlKey, event.target);
87 var editableContent = null;
88 var $e = $(event.target);
92 while( ($e[0] != this.element[0]) && !($e.attr('wl2o:editable'))
95 // console.log($e, $e.parent(), this.element);
100 if(!$e.attr('wl2o:editable'))
103 // start edition on this node
107 '<div class="html-editarea">\n\
108 <p class="html-editarea-toolbar">\n\
109 <button class="html-editarea-save-button" type="button">Zapisz</button>\n\
110 <button class="html-editarea-cancel-button" type="button">Anuluj</button>\n\
112 <textarea></textarea>\n\
115 var x = $e[0].offsetLeft;
116 var y = $e[0].offsetTop;
117 var w = $e.outerWidth();
118 var h = $e.innerHeight();
119 $overlay.css({position: 'absolute', height: h, left: "5%", top: y, width: "90%"});
120 $e.offsetParent().append($overlay);
122 // load the original XML content
123 console.log($e, $e.offsetParent(), $overlay);
125 $('.html-editarea-cancel-button', $overlay).click(function() {
129 $('.html-editarea-save-button', $overlay).click(function() {
132 // put the part back to the model
133 self.model.putXMLPart($e, $('textarea', $overlay).val());
136 $('textarea', $overlay).focus(function() {
137 $overlay.css('z-index', 3000);
139 $overlay.css('z-index', 2000);
142 this.model.getXMLPart($e, function(path, data) {
143 $('textarea', $overlay).val(data);
152 panels['html'] = HTMLView;