Pārlūkot izejas kodu

prevent re-activating active tab, save changes underway

Benoît Hubert 8 gadi atpakaļ
vecāks
revīzija
88117ced2a
1 mainītis faili ar 23 papildinājumiem un 17 dzēšanām
  1. 23 17
      js/ws-editor.js

+ 23 - 17
js/ws-editor.js

@@ -79,7 +79,12 @@ $(document).ready(function() {
 
 
   function onTabClicked(e) {
+    var clickedItem = $(e.target);
     var activeTab = _ws.ui.tabs.getActiveTab();
+    console.log('onTabClicked', clickedItem, activeTab);
+    if(activeTab[0] === clickedItem[0] || clickedItem[0].tagName === 'SPAN') {
+      return true;
+    }
     if(activeTab.hasClass('dirty')) {
       var proceed = window.confirm("Vos changements sur " + activeTab.data('name') +
         " seront perdus si vous changez de fichier. Continuer tout de même ?");
@@ -88,7 +93,6 @@ $(document).ready(function() {
       }
       activeTab.removeClass('dirty');
     }
-    var clickedItem = $(e.target);
     var type = clickedItem.data('type');
     editorSession.setMode("ace/mode/" + mapTypes[type]);
     var name = clickedItem.data('name');
@@ -111,12 +115,12 @@ $(document).ready(function() {
 
   _ws.makeView('tabs', {
     setActiveTab: function(file) {
-      var file = _ws.files.find(f => (f.name === file.name));
+      this.file = _ws.files.find(f => (f.name === file.name));
       if(this.activeTab) {
         this.activeTab.removeClass('bold');
       }
-      console.log('set active tab', idx, file);
-      var idx = this.fileIdx = _ws.files.indexOf(file);
+      console.log('set active tab', idx, this.file);
+      var idx = this.fileIdx = _ws.files.indexOf(this.file);
       this.activeTab = this.$elem.find('li:eq(' + idx + ')');
       this.activeTab.addClass('bold');
     },
@@ -124,7 +128,8 @@ $(document).ready(function() {
       return this.activeTab;
     },
     events: {
-      'click li[data-type]': onTabClicked
+      'click li[data-type]': onTabClicked,
+      'click li[data-type] span': onSaveChanges
     }
   })
 
@@ -143,7 +148,7 @@ $(document).ready(function() {
      * React to changes in editor by saving a copy
      */
     contentChanged: function() {
-      console.log('content changed handler');
+      console.log('content changed handler', editorSession.getValue());
       _ws.ui.tabs.getActiveTab()
       .addClass('dirty');
       // if(saveTimeout1 || saveTimeout2) {
@@ -197,17 +202,18 @@ $(document).ready(function() {
   //   location.reload();
   // }
 
-  // function saveChanges() {
-  //   var payload = editorStorage.getSources();
-  //   rp.put('/examples/' + currentHash, payload)
-  //   .then(function(newExample) {
-  //     notify('success', "Exemple sauvegardé !");
-  //     loadExample(currentHash);
-  //   })
-  //   .catch(function(err) {
-  //     notify('error', 'Erreur: ' + jqXHR.responseText);
-  //   });
-  // }
+  function onSaveChanges() {
+    console.log('Saving', this.file, editorSession.getValue())
+    // var payload = editorStorage.getSources();
+    // rp.put('/examples/' + currentHash, payload)
+    // .then(function(newExample) {
+    //   notify('success', "Exemple sauvegardé !");
+    //   loadExample(currentHash);
+    // })
+    // .catch(function(err) {
+    //   notify('error', 'Erreur: ' + jqXHR.responseText);
+    // });
+  }
 
   // $fileSelect.change(function() {
   //   loadExample($(this).val());