5942f25991db5f68b9380986e0dfbcf99b9f6028
[jra/samba/.git] / swat / scripting / client / regedit.js
1 /*
2         client side js functions for registry editing
3
4         Copyright Andrew Tridgell 2005
5         released under the GNU GPL Version 2 or later
6 */
7
8
9 /*
10   callback from the key enumeration call
11 */
12 function __folder_keys(fParent, list) 
13 {
14         var i;
15         if (fParent.working == 1) {
16                 fParent.working = 0;
17                 fParent.removeAll();
18         }
19         for (i=0;i<list.length;i++) {
20                 var fChild;
21                 fChild = new QxTreeFolder(list[i]);
22                 fParent.add(fChild);
23                 fChild.binding = fParent.binding;
24                 if (fParent.reg_path == '\\') {
25                         fChild.reg_path = list[i];
26                 } else {
27                         fChild.reg_path = fParent.reg_path + '\\' + list[i];
28                 }
29                 fChild.working = 1;
30                 fChild.add(new QxTreeFolder('Working ...'));
31                 fChild.addEventListener("click", function() { 
32                         var el = this; __folder_click(el); 
33                 });
34         }
35         fParent.setOpen(1);
36 }
37
38 /*
39   callback from the key enumeration call
40 */
41 function __folder_values(fParent, list) 
42 {
43         var i;
44         if (list.length == 0) {
45                 return;
46         }
47         if (fParent.working == 1) {
48                 fParent.working = 0;
49                 fParent.removeAll();
50         }
51         for (i=0;i<list.length;i++) {
52                 var fChild;
53                 fChild = new QxTreeFile(list[i].name);
54                 fChild.parent = fParent;
55                 fChild.details = list[i];
56                 fParent.add(fChild);
57         }
58         fParent.setOpen(1);
59 }
60
61 /*
62   called when someone clicks on a folder
63 */
64 function __folder_click(node) 
65 {
66         if (!node.populated) {
67                 node.populated = true;
68                 server_call_url("/scripting/server/regedit.esp", 'enum_keys', 
69                                 function(list) { __folder_keys(node, list); }, 
70                                 node.binding, node.reg_path);
71                 server_call_url("/scripting/server/regedit.esp", 'enum_values', 
72                                 function(list) { __folder_values(node, list); }, 
73                                 node.binding, node.reg_path);
74         }
75 }
76
77 /* return a registry tree for the given server */
78 function __registry_tree(binding) 
79 {
80         var tree = new QxTree("registry: " + binding);
81         tree.binding = binding;
82         tree.reg_path = "\\";
83         tree.populated = false;
84         with(tree) {
85                 setBackgroundColor(255);
86                 setBorder(QxBorder.presets.inset);
87                 setOverflow("scroll");
88                 setStyleProperty("padding", "2px");
89                 setWidth("50%");
90                 setHeight("90%");
91                 setTop("10%");
92         }
93         tree.addEventListener("click", function() { 
94                 var el = this; __folder_click(el); 
95         });
96         return tree;
97 }
98
99 /*
100   the table of values
101 */
102 function __values_table()
103 {
104         var headings = new Array("Name", "Type", "Size", "Value");
105         var table = document.createElement('table');
106         table.border = "1";
107         var body = document.createElement('tbody');
108         table.appendChild(body);
109         var th = document.createElement('th');
110         for (var i=0;i<headings.length;i++) {
111                 var td = document.createElement('td');
112                 td.appendChild(document.createTextNode(headings[i]));
113                 th.appendChild(td);
114         }
115         body.appendChild(th);
116         return table;
117 }
118
119 /*
120   create a registry editing widget and return it as a object
121 */
122 function regedit_widget(binding) 
123 {
124         var regedit = new QxWindow("Registry Editor");
125         regedit.setSpace(300, 600, 300, 600);
126
127         var fieldSet = new QxFieldSet();
128
129         regedit.binding = binding;
130
131         with(fieldSet) {
132                 setWidth("100%");
133                 setHeight("100%");
134         };
135
136         var gl = new QxGridLayout("auto,auto,auto,auto,auto", "50%,50%");
137         gl.setEdge(0);
138         gl.setCellPaddingTop(3);
139         gl.setCellPaddingBottom(3);
140
141         regedit.add(fieldSet);
142
143         var t = __registry_tree(regedit.binding);
144
145         function change_binding(e) {
146                 regedit.binding = e.getNewValue();
147                 srv_printf("changed binding to %s\\n", regedit.binding);
148                 gl.remove(t);
149                 t = __registry_tree(regedit.binding);
150                 gl.add(t, { row : 2, col : 1 });
151         }
152
153         var b = new QxTextField(regedit.binding);
154         b.addEventListener("changeText", change_binding);
155
156         var values = new __values_table();
157
158         gl.add(b,      { row : 1, col : 1 });
159         gl.add(t,      { row : 2, col : 1 });
160 //      gl.add(values, { row : 2, col : 2 });
161         
162         fieldSet.add(gl);
163         regedit.add(fieldSet);
164
165         /* 
166            call the startup() method to display the widget
167         */
168         regedit.startup = function() {
169                 this.setVisible(true);
170                 this.setMoveable(true);
171                 this.setResizeable(true);
172                 this.setResizeMethod("frame");
173                 this.setMoveable(true);
174         }
175
176         return regedit;
177 };