Działający przycisk "Commit".
authorzuber <marek@stepniowski.com>
Tue, 29 Sep 2009 11:57:02 +0000 (13:57 +0200)
committerzuber <marek@stepniowski.com>
Tue, 29 Sep 2009 11:57:02 +0000 (13:57 +0200)
project/static/js/models.js
project/static/js/views/editor.js
project/templates/explorer/editor.html

index 8ea488e..0402e6d 100644 (file)
@@ -230,7 +230,7 @@ Editor.DocumentModel = Editor.Model.extend({
     }
   },
   
-  quickSave: function(message) {
+  updateDirtyContentModel: function(message) {
     for (var key in this.contentModels) {
       if (this.contentModels[key].get('state') == 'dirty') {
         this.contentModels[key].update(message);
index 1e39ca5..49b5e02 100644 (file)
@@ -16,13 +16,77 @@ var EditorView = View.extend({
     
     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) {
-    this.model.quickSave();
+    this.model.updateDirtyContentModel();
   },
   
   commit: function(event) {
+    $('#commit-dialog', this.element).jqmShow({callback: this.doCommit.bind(this)});
+  },
+  
+  doCommit: function(message) {
+    this.model.updateDirtyContentModel(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();
   },
   
   update: function(event) {
index d075678..3a64e8d 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>
        
@@ -85,7 +89,7 @@
 {% 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 %}