Merge branch 'master' of stigma:platforma
authorŁukasz Rekucki <lrekucki@gmail.com>
Tue, 29 Sep 2009 14:13:49 +0000 (16:13 +0200)
committerŁukasz Rekucki <lrekucki@gmail.com>
Tue, 29 Sep 2009 14:13:49 +0000 (16:13 +0200)
1  2 
project/static/js/models.js
project/templates/explorer/editor.html

@@@ -104,6 -104,7 +104,7 @@@ Editor.XMLModel = Editor.Model.extend(
      this.set('state', 'dirty');
    },
    
+   // For debbuging
    set: function(property, value) {
      if (property == 'state') {
        console.log(this.description(), ':', property, '=', value);
@@@ -162,7 -163,8 +163,8 @@@ Editor.HTMLModel = Editor.Model.extend(
      this.set('data', data);
      this.set('state', 'synced');
    },
-   
+   // For debbuging
    set: function(property, value) {
      if (property == 'state') {
        console.log(this.description(), ':', property, '=', value);
  });
  
  
 +Editor.ImageGalleryModel = Editor.Model.extend({
 +  _className: 'Editor.ImageGalleryModel',
 +  serverURL: null,  
 +  state: 'empty',
 +
 +  init: function(serverURL) {
 +    this._super();
 +    this.set('state', 'empty');
 +    this.serverURL = serverURL;
 +    // olewać data    
 +    this.pages = []
 +  },
 +
 +  load: function() {
 +    if (this.get('state') == 'empty') {
 +      this.set('state', 'loading');
 +      $.ajax({
 +        url: this.serverURL,
 +        dataType: 'json',
 +        success: this.loadingSucceeded.bind(this)
 +      });
 +    }
 +  },  
 +
 +  loadingSucceeded: function(data) {
 +    if (this.get('state') != 'loading') {
 +      alert('erroneous state:', this.get('state'));
 +    }
 +
 +    this.set('pages', data.pages)      
 +    this.set('state', 'synced');
 +  },
 +
 +  set: function(property, value) {
 +    if (property == 'state') {
 +      console.log(this.description(), ':', property, '=', value);
 +    }
 +    return this._super(property, value);
 +  }
 +});
 +
 +
  Editor.DocumentModel = Editor.Model.extend({
    _className: 'Editor.DocumentModel',
    data: null, // name, text_url, latest_rev, latest_shared_rev, parts_url, dc_url, size
      this.set('state', 'synced');
      this.contentModels = {
        'xml': new Editor.XMLModel(data.text_url),
 -      'html': new Editor.HTMLModel(data.html_url)
 +      'html': new Editor.HTMLModel(data.html_url),
 +      'gallery': new Editor.ImageGalleryModel(data.gallery_url)
      };
      for (var key in this.contentModels) {
        this.contentModels[key].addObserver(this, 'state', this.contentModelStateChanged.bind(this));
    
    contentModelStateChanged: function(property, value, contentModel) {
      if (value == 'dirty') {
+       this.set('state', 'dirty');
        for (var key in this.contentModels) {
          if (this.contentModels[key].guid() != contentModel.guid()) {
-           // console.log(this.contentModels[key].description(), 'frozen');
            this.contentModels[key].set('state', 'unsynced');
          }
        }
+     } else if (value == 'updated') {
+       this.set('state', 'synced');
+       for (key in this.contentModels) {
+         if (this.contentModels[key].guid() == contentModel.guid()) {
+           this.contentModels[key].set('state', 'synced');
+         } else if (this.contentModels[key].get('state') == 'unsynced') {
+           this.contentModels[key].set('state', 'empty');
+         }
+       }
      }
    },
    
-   quickSave: function(message) {
+   saveDirtyContentModel: function(message) {
      for (var key in this.contentModels) {
        if (this.contentModels[key].get('state') == 'dirty') {
          this.contentModels[key].update(message);
          break;
        }
      }
+   },
+   
+   update: function() {
+     
+   },
+   
+   merge: function() {
+     
+   },
+   
+   // For debbuging
+   set: function(property, value) {
+     if (property == 'state') {
+       console.log(this.description(), ':', property, '=', value);
+     }
+     return this._super(property, value);
    }
  });
  
@@@ -1,12 -1,16 +1,16 @@@
  {% extends "base.html" %}
  
  {% block extrahead %}
+       <link rel="stylesheet" href="{{STATIC_URL}}css/jquery.modal.css" type="text/css" media="screen" title="no title" charset="utf-8">
        <link rel="stylesheet" href="{{STATIC_URL}}css/html.css" type="text/css" media="screen" title="no title" charset="utf-8">
+       
        <script type="text/javascript" charset="utf-8">
                var fileId = '{{ fileid }}';
        </script>
-     <script src="{{STATIC_URL}}js/lib/codemirror/codemirror.js" type="text/javascript" charset="utf-8"></script>
        
+       {# Libraries #}
+     <script src="{{STATIC_URL}}js/lib/codemirror/codemirror.js" type="text/javascript" charset="utf-8"></script>
+       <script src="{{STATIC_URL}}js/lib/jquery.modal.js" type="text/javascript" charset="utf-8"></script>
        {# Scriptlets #}
        <script src="http://localhost:8000/api/toolbar/scriptlets" type="text/javascript" charset="utf-8"></script>
        
@@@ -18,7 -22,6 +22,7 @@@
        <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/gallery.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/models.js" type="text/javascript" charset="utf-8"></script>
                <div class="htmlview">
                </div>
        </script>
 +
 +        <script type="text/html" charset="utf-8" id="image-gallery-view-template">
 +      <div class="image-gallery-view-template">
 +
 +        <div class="image-gallery-panel-header">
 +        <p>
 +        <button type="button" class="image-gallery-prev-button">Previous</button>
 +        <input type="input" class="image-gallery-current-page" />
 +        <button type="button" class="image-gallery-next-button">Next</button>
 +        </p>
 +        </div>
 +
 +        <div>
 +            <% for (page in panels) { %>
 +                <p>strona</p>
 +            <% }; %>
 +      </div>
 +        
 +        </div>
 +      </script>
        
        <script type="text/html" charset="utf-8" id="button-toolbar-view-template">
                <div class="buttontoolbarview">
  {% endblock %}
  
  {% block header-toolbar %}
-       <button id="action-update">Update</button> <button id="action-commit">Commit</button> <button id="action-quick-save">Quick Save</button>
+       <button id="action-merge">Merge</button> <button id="action-update">Update</button> <button id="action-commit">Commit</button> <button id="action-quick-save">Quick Save</button>
  {% endblock %}
  
  {% block maincontent %}
      </div>
  
  
-     {# <div id="commit-dialog" class="jqmWindow"> #}
-     {#     <form action="{% url file_commit fileid %}" method="POST"> #}
-     {#         <label for="message">Commit message:</label> #}
-     {#         <textarea cols="60" rows="10" name="message" id="commit-dialog-message"></textarea> #}
-     {#         <p id="commit-dialog-error-empty-message">Wiadomość nie może być pusta.</p>                 #}
-     {#         <fieldset id="commit-dialog-related-issues"  #}
-     {#                   ui:ajax-src="http://localhost:3000/publications/issues/{{fileid}}"> #}
-     {#             <legend>Related issues</legend> #}
-     {#             <div class="loading-box" style="display: none;"> #}
-     {#                 <p>Loading related issues...</p> #}
-     {#             </div> #}
-     {#             <div class="container-box">No related issues.</div> #}
-     {#         </fieldset> #}
-     {#         <p> #}
-     {#            <input type="button" value="Save" id="commit-dialog-save-button" /> #}
-     {#            <input type="reset" value="Cancel" id="commit-dialog-cancel-button" /> #}
-     {#         </p> #}
-     {#     </form> #}
-     {# </div> #}
-     {#  #}
-     {# <div id="split-dialog" class="jqmWindow"> #}
-     {#     <div class="container-box"> </div> #}
-     {#     <div class="loading-box" style="display: none;"> #}
-     {#         <p>Loading dialog contents...</p> #}
-     {#         <!-- <p><button type="button" class="dialog-close-button">Close</button></p> --> #}
-     {#     </div> #}
-     {#     <div class="fatal-error-box" style="display: none;"> #}
-     {#         <p>Server error, while loading dialog :(</p> #}
-     {#         <p><button type="button" class="dialog-close-button">Close</button></p> #}
-     {#     </div> #}
-     {# </div> #}
+     <div id="commit-dialog" class="jqmWindow" style="display:none">
+         <form action="{% url file_commit fileid %}" method="POST">
+             <label for="message">Commit message:</label>
+             <textarea cols="60" rows="10" name="message" id="commit-dialog-message"></textarea>
+             <p id="commit-dialog-error-empty-message">Wiadomość nie może być pusta.</p>                
+             <fieldset id="commit-dialog-related-issues" 
+                       ui:ajax-src="http://localhost:3000/publications/issues/{{fileid}}">
+                 <legend>Related issues</legend>
+                 <div class="loading-box" style="display: none;">
+                     <p>Loading related issues...</p>
+                 </div>
+                 <div class="container-box">No related issues.</div>
+             </fieldset>
+             <p>
+                <input type="button" value="Save" id="commit-dialog-save-button" />
+                <input type="reset" value="Cancel" id="commit-dialog-cancel-button" />
+             </p>
+         </form>
+     </div>
+     
+     <div id="split-dialog" class="jqmWindow" style="display:none">
+         <div class="container-box"> </div>
+         <div class="loading-box" style="display: none;">
+             <p>Loading dialog contents...</p>
+             <!-- <p><button type="button" class="dialog-close-button">Close</button></p> -->
+         </div>
+         <div class="fatal-error-box" style="display: none;">
+             <p>Server error, while loading dialog :(</p>
+             <p><button type="button" class="dialog-close-button">Close</button></p>
+         </div>
+     </div>
  {% endblock maincontent %}