r9635: Seperate window logic from registry js file.
authorDeryck Hodge <deryck@samba.org>
Fri, 26 Aug 2005 05:25:29 +0000 (05:25 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:34:36 +0000 (13:34 -0500)
This allows for flexibility in display format,
which will make more sense when I start working
on windows, tabs, etc.

Add the beginnings of a document.js object that allows
us to add and remove scripts as we use them, which will
ensure we only load what we need.  A desktop GUI runs
from a single page, so we can't load js files by changing
pages.

deryck
(This used to be commit b4f6f81d7bbf87fcb7c7c9bd4a7164aabaeedc1c)

swat/desktop/index.esp
swat/esptest/registry.esp
swat/scripting/client/js_scripts.js [new file with mode: 0644]
swat/scripting/client/regedit.js
swat/scripting/client/status.js

index 424f848..f688850 100644 (file)
@@ -4,8 +4,8 @@ libinclude("base.js");
 %>
 
 <script type="text/javascript" src="/scripting/client/encoder.js"></script>
-<script type="text/javascript" src="/scripting/client/regedit.js"></script>
-<script type="text/javascript" src="/scripting/client/status.js"></script>
+<script type="text/javascript" src="/scripting/client/call.js"></script>
+<script type="text/javascript" src="/scripting/client/js_scripts.js"></script>
 
 <script type="text/javascript">
 
@@ -91,6 +91,7 @@ function showContextMenu(e)
 }
 
 /*** init the page for qooxdoo ***/
+document.js.add('/scripting/client/status.js');
 window.application.main = function()
 {
        var doc = this.getClientWindow().getClientDocument();
@@ -108,6 +109,12 @@ window.application.main = function()
 
        // Always open with stats
        var win = new QxWindow();
+       win._onclosebuttonclick = function(e)
+       {
+               this.close();
+               e.stopPropagation();
+               document.js.remove('/scripting/client/status.js');
+       };
        with(win) {
                setTop(50);
                setRight(50);
@@ -126,9 +133,26 @@ window.onresize = function()
 
 function showReg()
 {
+       document.js.add('/scripting/client/regedit.js');
+
+       var regWin = new QxWindow("Registry Editor");
+       regWin._onclosebuttonclick = function(e)
+       {
+               this.close();
+               e.stopPropagation();
+               document.js.remove('/scripting/client/regedit.js');
+       };
+       with(regWin) {
+               setTop(100);
+               setLeft(100);
+               setMinWidth(450);
+               setMinHeight(450);
+       }
+       
        var regedit = regedit_widget("ncalrpc:");
-       w.add(regedit);
-       regedit.startup();
+       regWin.add(regedit);
+       w.add(regWin);
+       regWin.setVisible('true');
 }
 
 function startSwat()
index b65b5d1..efdfefc 100644 (file)
@@ -23,9 +23,20 @@ window.application.main = function()
     var btn1 = new QxButton("Registry Editor");
     btn1.set({ top: 20, left : 30 });
     btn1.addEventListener("click", function() {
+            var regWindow = new QxWindow("Registry Editor");
+           with(regWindow) {
+                setTop(50);
+               setLeft(50);
+                setMinWidth(600);
+               setMinHeight(600);
+               setResizeMethod("frame");
+           }
+
            var regedit = regedit_widget("ncalrpc:");
-           qwidget.add(regedit);
-           regedit.startup();
+           regWindow.add(regedit);
+           qwidget.add(regWindow);
+           regWindow.setVisible(true);
+
     });
     qwidget.add(btn1);
     inlineWidget.add(qwidget);
diff --git a/swat/scripting/client/js_scripts.js b/swat/scripting/client/js_scripts.js
new file mode 100644 (file)
index 0000000..776e5e4
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+   Beginnnigs of a script manager for SWAT.
+
+   Copyright (C) Deryck Hodge 2005
+   released under the GNU GPL Version 2 or later
+*/
+
+var head = document.getElementsByTagName('head')[0];
+var scripts = document.getElementsByTagName('script');
+
+function __has_js_script(file)
+{
+       var i;
+       for (i=0; i<scripts.length; i++) {
+               if (scripts[i].src.indexOf(file) > -1) {
+                       return true;
+               } else {
+                       return false;
+               }
+       }
+}
+
+function __get_js_script(file)
+{
+       var i;
+       for (i=0; i<scripts.length; i++) {
+               if (scripts[i].src.indexOf(file) > -1) {
+                       return scripts[i];
+               }
+       }
+}
+
+function __add_js_script(path)
+{
+       var script = document.createElement('script');
+       script.setAttribute('type', 'text/javascript');
+       script.setAttribute('src', path);
+       head.appendChild(script);
+}
+
+function __remove_js_script(path)
+{
+       var script = __get_js_script(path);
+       script.parentNode.removeChild(script);
+}
+
+document.js = new Object();
+document.js.scripts = scripts;
+document.js.hasScript = __has_js_script;
+document.js.getScript = __get_js_script;
+document.js.add = __add_js_script;
+document.js.remove = __remove_js_script;
+
index 5942f25..9175017 100644 (file)
@@ -121,12 +121,9 @@ function __values_table()
 */
 function regedit_widget(binding) 
 {
-       var regedit = new QxWindow("Registry Editor");
-       regedit.setSpace(300, 600, 300, 600);
-
        var fieldSet = new QxFieldSet();
 
-       regedit.binding = binding;
+       fieldSet.binding = binding;
 
        with(fieldSet) {
                setWidth("100%");
@@ -138,19 +135,17 @@ function regedit_widget(binding)
        gl.setCellPaddingTop(3);
        gl.setCellPaddingBottom(3);
 
-       regedit.add(fieldSet);
-
-       var t = __registry_tree(regedit.binding);
+       var t = __registry_tree(fieldSet.binding);
 
        function change_binding(e) {
-               regedit.binding = e.getNewValue();
-               srv_printf("changed binding to %s\\n", regedit.binding);
+               fieldSet.binding = e.getNewValue();
+               srv_printf("changed binding to %s\\n", fieldSet.binding);
                gl.remove(t);
-               t = __registry_tree(regedit.binding);
+               t = __registry_tree(fieldSet.binding);
                gl.add(t, { row : 2, col : 1 });
        }
 
-       var b = new QxTextField(regedit.binding);
+       var b = new QxTextField(fieldSet.binding);
        b.addEventListener("changeText", change_binding);
 
        var values = new __values_table();
@@ -160,18 +155,6 @@ function regedit_widget(binding)
 //     gl.add(values, { row : 2, col : 2 });
        
        fieldSet.add(gl);
-       regedit.add(fieldSet);
-
-       /* 
-          call the startup() method to display the widget
-       */
-       regedit.startup = function() {
-               this.setVisible(true);
-               this.setMoveable(true);
-               this.setResizeable(true);
-               this.setResizeMethod("frame");
-               this.setMoveable(true);
-       }
 
-       return regedit;
+       return fieldSet;
 };
index fa2c3b5..9be85ac 100644 (file)
@@ -5,15 +5,6 @@
 */
 
 
-/* Ensure we always include the proper libs
-   Playing with a way to add/del scripts on the fly...
-*/
-var lib = document.createElement('script');
-lib.setAttribute('type', 'text/javascript');
-lib.setAttribute('src', '/scripting/client/call.js');
-var head = document.getElementsByTagName('head')[0];
-head.appendChild(lib);
-
 // Format for a server status table
 var s = [
        { id : "server",