r4108 UI: VST editor: show attention message when unsaved tamplate is displayed
authorAlexey Andriyanov <alan@al-an.info>
Wed, 12 Jan 2011 10:50:22 +0000 (10:50 +0000)
committerAlexey Andriyanov <alan@al-an.info>
Wed, 12 Jan 2011 10:50:22 +0000 (10:50 +0000)
js/vst_editor.js

index 5faa13e..5214dbe 100644 (file)
@@ -3,7 +3,9 @@
 $(document).ready(function() {
        $('a.vst-add-rule').click(AddVSTRule)
        $('a.vst-del-rule').click(RemoveVSTRule)
-       $('form#upd').submit(VSTSubmit);
+       $('form#upd')
+               .submit(VSTSubmit)
+               .change(highlightUnsavedVST);
 });
 
 function AddVSTRule(event) {
@@ -17,11 +19,13 @@ function AddVSTRule(event) {
        new_tr.find('a.vst-add-rule').click(AddVSTRule);
        new_tr.find('a.vst-del-rule').click(RemoveVSTRule);
 
+       highlightUnsavedVST();
        return false;
 }
 
 function RemoveVSTRule(event) {
        $(this).closest('tr').remove();
+       highlightUnsavedVST();
        return false;
 }
 
@@ -38,3 +42,12 @@ function VSTSubmit() {
        $(this).find('input[name|="template_json"]').val(JSON.stringify(result));
        return true;
 }
+
+function highlightUnsavedVST() {
+    // highlight only on first call of this function
+    if ( typeof highlightUnsavedVST.isAlreadyCalled == 'undefined' ) {
+        highlightUnsavedVST.isAlreadyCalled = true;
+               $('input[name|="submit"]').before('<div class="msg_warning">Template is unsaved. Click here to save it</div>');
+               console.log('a');
+    }
+}