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) {
29 if (value == 'synced' || value == 'dirty') {
31 } else if (value == 'unsynced') {
32 this.freeze('Niezsynchronizowany...');
33 } else if (value == 'loading') {
34 this.freeze('Ćadowanie...');
35 } else if (value == 'saving') {
36 this.freeze('Zapisywanie...');
37 } else if (value == 'error') {
38 this.freeze(this.model.get('error'));
43 this.element.unbind('click');
45 if(this.$printLink) this.$printLink.unbind();
47 this.$printLink = $('.html-print-link', this.element);
49 var base = this.$printLink.attr('ui:baseref');
50 this.$printLink.attr('href', base + "?revision=" + this.model.get('revision'));
52 this.element.bind('click', this.itemClicked.bind(this));
56 this.model.load(true);
60 this.model.removeObserver(this);
64 itemClicked: function(event)
68 console.log('click:', event, event.ctrlKey, event.target);
69 var editableContent = null;
70 var $e = $(event.target);
74 while( ($e[0] != this.element[0]) && !($e.attr('wl2o:editable'))
77 // console.log($e, $e.parent(), this.element);
82 if(!$e.attr('wl2o:editable'))
85 // start edition on this node
89 '<div class="html-editarea">\n\
90 <p class="html-editarea-toolbar">\n\
91 <button class="html-editarea-save-button" type="button">Zapisz</button>\n\
92 <button class="html-editarea-cancel-button" type="button">Anuluj</button>\n\
94 <textarea></textarea>\n\
97 var x = $e[0].offsetLeft;
98 var y = $e[0].offsetTop;
99 var w = $e.outerWidth();
100 var h = $e.innerHeight();
101 $overlay.css({position: 'absolute', height: h, left: "5%", top: y, width: "90%"});
102 $e.offsetParent().append($overlay);
104 // load the original XML content
105 console.log($e, $e.offsetParent(), $overlay);
107 $('.html-editarea-cancel-button', $overlay).click(function() {
111 $('.html-editarea-save-button', $overlay).click(function() {
114 // put the part back to the model
115 self.model.putXMLPart($e, $('textarea', $overlay).val());
118 $('textarea', $overlay).focus(function() {
119 $overlay.css('z-index', 3000);
121 $overlay.css('z-index', 2000);
124 this.model.getXMLPart($e, function(path, data) {
125 $('textarea', $overlay).val(data);
134 panels['html'] = HTMLView;