Convert some more files to GPLv3.
[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 3 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 fieldSet = new QxFieldSet();
125
126         fieldSet.binding = binding;
127
128         with(fieldSet) {
129                 setWidth("100%");
130                 setHeight("100%");
131         };
132
133         var gl = new QxGridLayout("auto,auto,auto,auto,auto", "50%,50%");
134         gl.setEdge(0);
135         gl.setCellPaddingTop(3);
136         gl.setCellPaddingBottom(3);
137
138         var t = __registry_tree(fieldSet.binding);
139
140         function change_binding(e) {
141                 fieldSet.binding = e.getNewValue();
142                 srv_printf("changed binding to %s\\n", fieldSet.binding);
143                 gl.remove(t);
144                 t = __registry_tree(fieldSet.binding);
145                 gl.add(t, { row : 2, col : 1 });
146         }
147
148         var b = new QxTextField(fieldSet.binding);
149         b.addEventListener("changeText", change_binding);
150
151         var values = new __values_table();
152
153         gl.add(b,      { row : 1, col : 1 });
154         gl.add(t,      { row : 2, col : 1 });
155 //      gl.add(values, { row : 2, col : 2 });
156         
157         fieldSet.add(gl);
158
159         return fieldSet;
160 };