Dodanie zamrażania i odmrażania modeli i widoków.
authorzuber <marek@stepniowski.com>
Fri, 25 Sep 2009 14:08:20 +0000 (16:08 +0200)
committerzuber <marek@stepniowski.com>
Fri, 25 Sep 2009 14:08:20 +0000 (16:08 +0200)
project/static/css/master.css
project/static/js/app.js
project/static/js/views/html.js
project/static/js/views/panel_container.js
project/static/js/views/split.js
project/static/js/views/view.js [new file with mode: 0644]
project/static/js/views/xml.js
project/templates/explorer/editor.html

index 85e718e..d554a5f 100644 (file)
@@ -384,3 +384,19 @@ text#commit-dialog-message {
 .xmlview {
     height: 100%;
 }
 .xmlview {
     height: 100%;
 }
+
+.view-overlay {
+    z-index: 1000;
+    background: #FFF;
+    opacity: 0.8;
+    text-align: center;
+    text-valign: center;
+}
+
+.view-overlay p {
+    display: block;
+    position: relative;
+    top: auto;
+    bottom: auto;
+    height: 40px;
+}
\ No newline at end of file
index d2a7577..cfac503 100644 (file)
@@ -128,6 +128,7 @@ var DocumentModel = Class.extend({
   },
   
   getXML: function(callback) {
   },
   
   getXML: function(callback) {
+      $(this).trigger('modelxmlfreeze');
     if (!this.data) {
       this.getData(this.getXML);
     } else {
     if (!this.data) {
       this.getData(this.getXML);
     } else {
@@ -147,6 +148,7 @@ var DocumentModel = Class.extend({
       this.modelChanged();
       $(this).trigger('modelxmlchanged');
     }
       this.modelChanged();
       $(this).trigger('modelxmlchanged');
     }
+    $(this).trigger('modelxmlunfreeze');
   },
   
   modelChanged: function() {
   },
   
   modelChanged: function() {
index 65c8af0..cd32ced 100644 (file)
@@ -1,5 +1,5 @@
-/*global Class render_template panels */
-var HTMLView = Class.extend({
+/*global View render_template panels */
+var HTMLView = View.extend({
   element: null,
   model: null,
   template: 'html-view-template',
   element: null,
   model: null,
   template: 'html-view-template',
@@ -12,7 +12,7 @@ var HTMLView = Class.extend({
   },
   
   dispose: function() {
   },
   
   dispose: function() {
-    
+    this._super();
   }
 });
 
   }
 });
 
index 4823343..c873574 100644 (file)
@@ -1,6 +1,6 @@
-/*globals Class render_template panels*/
+/*globals View render_template panels*/
 
 
-var PanelContainerView = Class.extend({
+var PanelContainerView = View.extend({
   element: null,
   model: null,
   template: 'panel-container-view-template',
   element: null,
   model: null,
   template: 'panel-container-view-template',
@@ -29,6 +29,7 @@ var PanelContainerView = Class.extend({
   
   dispose: function() {
     $('select', this.element.get(0)).unbind('change.panel-container-view');
   
   dispose: function() {
     $('select', this.element.get(0)).unbind('change.panel-container-view');
+    this._super();
   }
 });
 
   }
 });
 
index 8e6fa20..cc0d361 100644 (file)
@@ -1,7 +1,7 @@
-/*globals Class*/
+/*globals View*/
 
 // Split view inspired by jQuery Splitter Plugin http://methvin.com/splitter/
 
 // Split view inspired by jQuery Splitter Plugin http://methvin.com/splitter/
-var SplitView = Class.extend({
+var SplitView = View.extend({
   splitbarClass: 'splitview-splitbar',
   activeClass: 'splitview-active',
   overlayClass: 'splitview-overlay',
   splitbarClass: 'splitview-splitbar',
   activeClass: 'splitview-active',
   overlayClass: 'splitview-overlay',
@@ -100,6 +100,7 @@ var SplitView = Class.extend({
   
   dispose: function() {
     this.splitter.unbind('mousedown.splitview');
   
   dispose: function() {
     this.splitter.unbind('mousedown.splitview');
+    this._super();
   }
 });
 
   }
 });
 
diff --git a/project/static/js/views/view.js b/project/static/js/views/view.js
new file mode 100644 (file)
index 0000000..975eeb9
--- /dev/null
@@ -0,0 +1,53 @@
+/*globals Class render_template*/
+var View = Class.extend({
+  element: null,
+  model: null,
+  template: null,
+  overlayClass: 'view-overlay',
+  overlay: null,
+
+  init: function(element, model, template) {
+    this.element = $(element);
+    this.model = model;
+    this.template = template || this.template;
+    
+    if (this.template) {
+      this.element.html(render_template(this.template, {}));
+    }
+  },
+
+  frozen: function() {
+    return !!this.overlay;
+  },
+  
+  freeze: function(message) {
+    this.overlay = this.overlay 
+      || $('<div><div>' + message + '</div></div>')
+            .addClass(this.overlayClass)
+            .css({
+              position: 'absolute',
+              width: this.element.width(),
+              height: this.element.height(),
+              top: this.element.position().top,
+              left: this.element.position().left
+            })
+            .appendTo(this.element.parent());
+            
+    this.overlay.children('div').css({
+      position: 'relative',
+      top: this.overlay.height() / 2 - 20
+    });
+  },
+  
+  unfreeze: function() {
+    if (this.frozen()) {
+      this.overlay.remove();
+      this.overlay = null;      
+    }
+  },
+
+  dispose: function() {
+    this.unfreeze();
+    this.element.contents().remove();
+  }
+});
index 78f8380..de3131c 100644 (file)
@@ -1,5 +1,5 @@
-/*global Class CodeMirror render_template panels */
-var XMLView = Class.extend({
+/*global View CodeMirror render_template panels */
+var XMLView = View.extend({
   element: null,
   model: null,
   template: 'xml-view-template',
   element: null,
   model: null,
   template: 'xml-view-template',
@@ -12,12 +12,21 @@ var XMLView = Class.extend({
     this.template = template || this.template;
     this.element.html(render_template(this.template, {}));
     
     this.template = template || this.template;
     this.element.html(render_template(this.template, {}));
     
-    var self = this;
+    $(this.model)
+      .bind('modelxmlfreeze.xmlview',
+        function() { this.freeze('Ładowanie danych z serwera...'); }.bind(this))
+      .bind('modelxmlunfreeze.xmlview',
+        this.unfreeze.bind(this));
+    
+    this.freeze('Ładowanie edytora...');
        this.editor = new CodeMirror($('.xmlview', this.element).get(0), {
       parserfile: 'parsexml.js',
       path: "/static/js/lib/codemirror/",
       stylesheet: "/static/css/xmlcolors.css",
       parserConfig: {useHTMLKludges: false},
        this.editor = new CodeMirror($('.xmlview', this.element).get(0), {
       parserfile: 'parsexml.js',
       path: "/static/js/lib/codemirror/",
       stylesheet: "/static/css/xmlcolors.css",
       parserConfig: {useHTMLKludges: false},
+      textWrapping: false,
+      tabMode: 'spaces',
+      indentUnit: 0,
       // onChange: function() {
       //        self.fireEvent('contentChanged');
       // },
       // onChange: function() {
       //        self.fireEvent('contentChanged');
       // },
@@ -31,6 +40,7 @@ var XMLView = Class.extend({
     $(editor.frame).css({width: '100%', height: '100%'});
     this.editor.setCode(this.model.xml);
     $(this.model).bind('modelxmlchanged.xmlview', this.codeChanged.bind(this));
     $(editor.frame).css({width: '100%', height: '100%'});
     this.editor.setCode(this.model.xml);
     $(this.model).bind('modelxmlchanged.xmlview', this.codeChanged.bind(this));
+    this.unfreeze();
     this.model.getXML();
     // editor.grabKeys(
     //   $.fbind(self, self.hotkeyPressed),
     this.model.getXML();
     // editor.grabKeys(
     //   $.fbind(self, self.hotkeyPressed),
@@ -41,11 +51,16 @@ var XMLView = Class.extend({
   codeChanged: function() {
     console.log('setCode:', this.editor, this.model);
     this.editor.setCode(this.model.xml);
   codeChanged: function() {
     console.log('setCode:', this.editor, this.model);
     this.editor.setCode(this.model.xml);
+    this.unfreeze();
   },
   
   dispose: function() {
   },
   
   dispose: function() {
-    $(this.model).unbind('modelxmlchanged.xmlview');
+    $(this.model)
+      .unbind('modelxmlchanged.xmlview')
+      .unbind('modelxmlfreeze.xmlview')
+      .unbind('modelxmlunfreeze.xmlview');
     $(this.editor.frame).remove();
     $(this.editor.frame).remove();
+    this._super();
   }
 });
 
   }
 });
 
index d2c5ba8..c743308 100644 (file)
     <script src="{{STATIC_URL}}js/lib/jquery.json.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/lib/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/lib/jquery.modal.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/lib/jquery.json.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/lib/jquery.cookie.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/lib/jquery.modal.js" type="text/javascript" charset="utf-8"></script>
+       
+       {# App and views #}
        <script src="{{STATIC_URL}}js/app.js" type="text/javascript" charset="utf-8"></script>
        <script src="{{STATIC_URL}}js/app.js" type="text/javascript" charset="utf-8"></script>
+       <script src="{{STATIC_URL}}js/views/view.js" type="text/javascript" charset="utf-8"></script>
        <script src="{{STATIC_URL}}js/views/split.js" type="text/javascript" charset="utf-8"></script>
        <script src="{{STATIC_URL}}js/views/xml.js" type="text/javascript" charset="utf-8"></script>
        <script src="{{STATIC_URL}}js/views/html.js" type="text/javascript" charset="utf-8"></script>
        <script src="{{STATIC_URL}}js/views/panel_container.js" type="text/javascript" charset="utf-8"></script>
        <script src="{{STATIC_URL}}js/views/split.js" type="text/javascript" charset="utf-8"></script>
        <script src="{{STATIC_URL}}js/views/xml.js" type="text/javascript" charset="utf-8"></script>
        <script src="{{STATIC_URL}}js/views/html.js" type="text/javascript" charset="utf-8"></script>
        <script src="{{STATIC_URL}}js/views/panel_container.js" type="text/javascript" charset="utf-8"></script>
+       
     <script src="{{STATIC_URL}}js/editor.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/editor.ui.js" type="text/javascript" charset="utf-8"></script>
 
     <script src="{{STATIC_URL}}js/editor.js" type="text/javascript" charset="utf-8"></script>
     <script src="{{STATIC_URL}}js/editor.ui.js" type="text/javascript" charset="utf-8"></script>