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)
project/static/css/html.css [new file with mode: 0644]
project/static/js/models.js
project/static/js/views/editor.js
project/static/js/views/xml.js
project/templates/explorer/editor.html

diff --git a/project/static/css/html.css b/project/static/css/html.css
new file mode 100644 (file)
index 0000000..8573449
--- /dev/null
@@ -0,0 +1,222 @@
+.htmlview {
+    font-size: 16px;
+    font: Georgia, "Times New Roman", serif;
+    line-height: 1.5em;
+    margin: 0;
+    margin: 3em;
+    max-width: 36em;
+}
+
+.htmlview #toc {
+    display: none;
+}
+
+.htmlview a {
+    color: blue;
+    text-decoration: none;
+}
+
+.htmlview h1 {
+    font-size: 3em;
+    margin: 1.5em 0;
+    text-align: center;
+    line-height: 1.5em;
+    font-weight: bold;
+}
+
+.htmlview h2 {
+    font-size: 2em;
+    margin: 1.5em 0 0;
+    font-weight: bold;
+    line-height: 1.5em;
+}
+
+.htmlview h3 {
+    font-size: 1.5em;
+    margin: 1.5em 0 0;
+    font-weight: normal;
+    line-height: 1.5em;
+}
+
+.htmlview h4 {
+    font-size: 1em;
+    margin: 1.5em 0 0;
+    line-height: 1.5em;
+}
+
+.htmlview p {
+    margin: 0;
+}
+
+/* ======================== */
+/* = Footnotes and themes = */
+/* ======================== */
+.htmlview .theme-begin {
+    border-left: 0.1em solid #DDDDDD;
+    color: #777;
+    padding: 0 0.5em;
+    width: 7.5em;
+    font-style: normal;
+    font-weight: normal;
+    font-size: 16px;
+    float: right;
+    margin-right: -9.5em;
+    clear: both;
+    left: 40em;
+    line-height: 1.5em;
+    text-align: left;
+}
+
+.htmlview .annotation {
+    font-style: normal;
+    font-weight: normal;
+    font-size: 12px;
+}
+
+.htmlview #footnotes .annotation {
+    display: block;
+    float: left;
+    width: 2.5em;
+    clear: both;
+}
+
+.htmlview #footnotes div {
+    margin: 1.5em 0 0 0;
+}
+
+.htmlview #footnotes p {
+    margin-left: 2.5em;
+    font-size: 0.875em;
+}
+
+.htmlview blockquote {
+    font-size: 0.875em;
+}
+
+/* ============= */
+/* = Numbering = */
+/* ============= */
+.htmlview .anchor {
+    position: absolute;
+    margin: -0.25em -0.5em;
+    left: 1em;
+    color: #777;
+    font-size: 12px;
+    width: 2em;
+    text-align: center;
+    padding: 0.25em 0.5em;
+    line-height: 1.5em;
+}
+
+.htmlview .anchor:hover, .htmlview .anchor:active {
+    color: #FFF;
+    background-color: #CCC;
+}
+
+/* =================== */
+/* = Custom elements = */
+/* =================== */
+.htmlview span.author {
+    font-size: 0.5em;
+    display: block;
+    line-height: 1.5em;
+    margin-bottom: 0.25em;
+}
+
+.htmlview span.collection {
+    font-size: 0.375em;
+    display: block;
+    line-height: 1.5em;
+    margin-bottom: -0.25em;
+}
+
+.htmlview span.subtitle {
+    font-size: 0.5em;
+    display: block;
+    line-height: 1.5em;
+    margin-top: -0.25em;
+}
+
+.htmlview div.didaskalia {
+    font-style: italic;
+    margin: 0.5em 0 0 1.5em;
+}
+
+.htmlview div.kwestia {
+    margin: 0.5em 0 0;
+}
+
+.htmlview div.stanza {
+    margin: 1.5em 0 0;
+}
+
+.htmlview div.kwestia div.stanza {
+    margin: 0;
+}
+
+.htmlview p.paragraph {
+    text-align: justify;
+    margin: 1.5em 0 0;
+}
+
+.htmlview p.motto {
+    text-align: justify;
+    font-style: italic;
+    margin: 1.5em 0 0;
+}
+
+.htmlview p.motto_podpis {
+    font-size: 0.875em;
+    text-align: right;
+}
+
+.htmlview div.fragment {
+    border-bottom: 0.1em solid #999;
+    padding-bottom: 1.5em;
+}
+
+.htmlview div.note p, .htmlview div.dedication p,
+.htmlview div.note p.paragraph, .htmlview div.dedication p.paragraph {
+    text-align: right;
+    font-style: italic;
+}
+
+.htmlview hr.spacer {
+    height: 3em;
+    visibility: hidden;
+}
+
+.htmlview hr.spacer-line {
+    margin: 1.5em 0;
+    border: none;
+    border-bottom: 0.1em solid #000;
+}
+
+.htmlview p.spacer-asterisk {
+    padding: 0;
+    margin: 1.5em 0;
+    text-align: center;
+}
+
+.htmlview div.person-list ol {
+    list-style: none;
+    padding: 0 0 0 1.5em;
+}
+
+.htmlview p.place-and-time {
+    font-style: italic;
+}
+
+.htmlview em.math, .htmlview em.foreign-word,
+.htmlview em.book-title, .htmlview em.didaskalia {
+    font-style: italic;
+}
+
+.htmlview em.author-emphasis {
+    letter-spacing: 0.1em;
+}
+
+.htmlview em.person {
+    font-style: normal;
+    font-variant: small-caps;
+}
index d0de300..62d1c78 100644 (file)
@@ -104,6 +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 @@ 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);
@@ -253,22 +255,47 @@ Editor.DocumentModel = Editor.Model.extend({
   
   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);
   }
 });
 
index 27b17cb..04e22c8 100644 (file)
@@ -9,29 +9,125 @@ var EditorView = View.extend({
     this._super(element, model, template);
     this.model.load();
     
-    $('#action-quick-save', this.element).bind('click.editorview', this.quickSave.bind(this));
-    $('#action-commit', this.element).bind('click.editorview', this.commit.bind(this));
-    $('#action-update', this.element).bind('click.editorview', this.update.bind(this));
-    this.freeze('Ładowanie');
+    this.quickSaveButton = $('#action-quick-save', this.element).bind('click.editorview', this.quickSave.bind(this));
+    this.commitButton = $('#action-commit', this.element).bind('click.editorview', this.commit.bind(this));
+    this.updateButton = $('#action-update', this.element).bind('click.editorview', this.update.bind(this));
+    this.mergeButton = $('#action-merge', this.element).bind('click.editorview', this.merge.bind(this));
+    
+    this.model.addObserver(this, 'state', this.modelStateChanged.bind(this));
+    this.modelStateChanged('state', this.model.get('state'));
+    
+    // Inicjalizacja okien jQuery Modal
+    $('#commit-dialog', this.element).
+    jqm({
+        modal: true,
+        onShow: this.loadRelatedIssues.bind(this)
+    });
+    
+    $('#commit-dialog-cancel-button', this.element).click(function() {
+        $('#commit-dialog-error-empty-message').hide();
+        $('#commit-dialog').jqmHide();
+    });   
+    
+    // $('#split-dialog').jqm({
+    //      modal: true,
+    //      onShow: $.fbind(self, self.loadSplitDialog)
+    //  }).
+    //  jqmAddClose('button.dialog-close-button');
   },
   
   quickSave: function(event) {
-    console.log('quickSave');
-    this.model.quickSave();
+    this.model.updateDirtyContentModel();
   },
   
   commit: function(event) {
-    console.log('commit');
+    $('#commit-dialog', this.element).jqmShow({callback: this.doCommit.bind(this)});
+  },
+  
+  doCommit: function(message) {
+    this.model.saveDirtyContentModel(message);
   },
   
   update: function(event) {
-    console.log('update');
+    this.model.update();
+  },
+  
+  merge: function(event) {
+    $('#commit-dialog', this.element).jqmShow({callback: this.doMerge.bind(this)});
+  },
+  
+  doMerge: function(message) {
+    this.model.merge(message);
+  },
+  
+  loadRelatedIssues: function(hash) {
+    var self = this;
+    var c = $('#commit-dialog-related-issues');
+
+    $('#commit-dialog-save-button').click(function(event, data)
+    {
+      if ($('#commit-dialog-message').val().match(/^\s*$/)) {
+        $('#commit-dialog-error-empty-message').fadeIn();
+      } else {
+        $('#commit-dialog-error-empty-message').hide();
+        $('#commit-dialog').jqmHide();
+
+        var message = $('#commit-dialog-message').val();
+        $('#commit-dialog-related-issues input:checked')
+          .each(function() { message += ' refs #' + $(this).val(); });
+        console.log("COMMIT APROVED", hash.t);
+        hash.t.callback(message);
+      }
+      return false;
+    });
+
+    $("div.loading-box", c).show();
+    $("div.fatal-error-box", c).hide();
+    $("div.container-box", c).hide();
+    
+    $.getJSON(c.attr('ui:ajax-src') + '?callback=?',
+    function(data, status)
+    {
+        var fmt = '';
+        $(data).each( function() {
+            fmt += '<label><input type="checkbox" checked="checked"';
+            fmt += ' value="' + this.id + '" />' + this.subject +'</label>\n';
+        });
+        $("div.container-box", c).html(fmt);
+        $("div.loading-box", c).hide();
+        $("div.container-box", c).show();        
+    });   
+    
+    hash.w.show();
+  },
+  
+  modelStateChanged: function(property, value) {
+    // Uaktualnia stan przycisków
+    if (value == 'dirty') {
+      this.quickSaveButton.attr('disabled', null);
+      this.commitButton.attr('disabled', null);
+      this.updateButton.attr('disabled', 'disabled');
+      this.mergeButton.attr('disabled', 'disabled');
+    } else if (value == 'synced') {
+      this.quickSaveButton.attr('disabled', 'disabled');
+      this.commitButton.attr('disabled', 'disabled');
+      this.updateButton.attr('disabled', null);
+      this.mergeButton.attr('disabled', null);      
+    } else if (value == 'empty') {
+      this.quickSaveButton.attr('disabled', 'disabled');
+      this.commitButton.attr('disabled', 'disabled');
+      this.updateButton.attr('disabled', 'disabled');
+      this.mergeButton.attr('disabled', 'disabled');
+    }
   },
   
   dispose: function() {
     $('#action-quick-save', this.element).unbind('click.editorview');
     $('#action-commit', this.element).unbind('click.editorview');
     $('#action-update', this.element).unbind('click.editorview');
+    $('#action-merge', this.element).unbind('click.editorview');
+
+    this.model.removeObserver(this);
     this._super();
   }
 });
index 6b7571a..8af3c4d 100644 (file)
@@ -58,7 +58,6 @@ var XMLView = View.extend({
   },
   
   modelDataChanged: function(property, value) {
-    console.log('modelDataChanged');
     if (this.editor.getCode() != value) {
       this.editor.setCode(value);
     }
index 7cb23a7..de1e242 100644 (file)
@@ -1,12 +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>
        
 {% 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 %}