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();
25 $("*[x-editable]").each(function() {
26 var e = $('<span class="context-menu"><span class="edit-button">Edytuj</span><span>Przypisy</span></span>');
31 updatePrintLink: function() {
32 var base = this.$printLink.attr('ui:baseref');
33 this.$printLink.attr('href', base + "?user="+this.model.document.get('user')+"&revision=" + this.model.get('revision'));
36 modelStateChanged: function(property, value)
40 if (value == 'synced' || value == 'dirty') {
42 } else if (value == 'unsynced') {
43 this.freeze('Niezsynchronizowany...');
44 } else if (value == 'loading') {
45 this.freeze('Ćadowanie...');
46 } else if (value == 'saving') {
47 this.freeze('Zapisywanie...');
48 } else if (value == 'error') {
49 this.freeze(this.model.get('error'));
50 $('.xml-editor-ref', this.overlay).click(
52 console.log("Sending scroll rq.", this);
54 var href = $(this).attr('href').split('-');
55 var line = parseInt(href[1]);
56 var column = parseInt(href[2]);
58 $(document).trigger('xml-scroll-request', {line:line, column:column});
69 this.element.unbind('click');
71 if(this.$printLink) this.$printLink.unbind();
73 this.$printLink = $('.html-print-link', this.element);
74 this.updatePrintLink();
76 this.element.bind('click', this.itemClicked.bind(this));
77 // this.element.bind('mouseover', this.itemHover.bind(this));
81 this.model.load(true);
85 this.model.removeObserver(this);
89 itemHover: function(event)
91 var $e = $(event.target);
92 if( $e.attr('x-editable') == 'editable' ) {
93 console.log('over:', $e[0]);
94 $e.css({'background-color': 'grey'});
99 itemClicked: function(event)
103 console.log('click:', event, event.ctrlKey, event.target);
104 var editableContent = null;
105 var $e = $(event.target);
107 if($e.hasClass('edit-button'))
108 this.openForEdit($e);
111 openForEdit: function($e)
115 while( ($e[0] != this.element[0]) && !($e.attr('x-editable'))
118 // console.log($e, $e.parent(), this.element);
123 if(!$e.attr('x-editable'))
127 console.log("editable: ", $e);
129 // start edition on this node
131 '<div class="html-editarea">\n\
132 <p class="html-editarea-toolbar">\n\
133 <button class="html-editarea-save-button" type="button">Zapisz</button>\n\
134 <button class="html-editarea-cancel-button" type="button">Anuluj</button>\n\
136 <textarea></textarea>\n\
139 var x = $e[0].offsetLeft;
140 var y = $e[0].offsetTop;
141 var w = $e.outerWidth();
142 var h = $e.innerHeight();
143 $overlay.css({position: 'absolute', height: 1.2*h, left: x, top: y, width: w});
144 // $e.offsetParent().append($overlay);
148 /* $('.html-editarea-cancel-button', $overlay).click(function() {
152 $('.html-editarea-save-button', $overlay).click(function() {
155 // put the part back to the model
156 self.model.putXMLPart($e, $('textarea', $overlay).val());
159 this.model.getXMLPart($e, function(path, data) {
160 $('textarea', $overlay).val(data);
163 $origin.attr('x-open', 'open');
170 panels['html'] = HTMLView;