/* --------------------------------------- --------------------------------------- GLOBAL VARIABLES dlg := Is used to show error messages, you don't have to configure anything. template := Here you can define your own button template to use with this script, if you don't want to use an extra file or the clipboard, just remember to put each line between single quotes, just like in the example below. state,line := If the toolbar is not open on the current Lister or the script can't get their state or line number, those are the default values to use. */ var template = ""; template = [ '', '' ].join("\r\n"); var state = "top"; var line = 1; var dlg = DOpus.dlg; function OnInit(initData) { initData.name = "Sites"; initData.desc = ""; initData.copyright = ""; var cmd = initData.AddCommand(); cmd.name = "Sites"; cmd.method = "Sites"; cmd.desc = ""; cmd.label = "Sites"; cmd.template = "TOOLBARNAME/K,POS/K/N,CONFIRM/S,PATHS/K/M,TEMPLATE/K[,clip],GUI/S,USEDISKLABELS/S"; } function Sites(c) { //Configure the dialog to show info/errors dlg.title = "Error"; dlg.icon = "error"; dlg.buttons = "Ok"; dlg.window = c.func.sourcetab.lister; var paths = c.func.args.PATHS; if (paths != undefined) { var template = getTemplate(String(c.func.args.TEMPLATE)); var nodes = (c.func.args.got_arg.GUI) ? Add_with_GUI(paths, template, c.func.args.got_arg.USEDISKLABELS) : Add_Paths(c.func.Dlg, paths, template, c.func.args.got_arg.CONFIRM); if (nodes.childNodes.length > 0) Do_The_Toolbar_Thing(c.func.args.TOOLBARNAME, nodes, c.func.args.POS, c.func.sourcetab.lister.toolbars, c.func.command); else alert("No buttons to add", "info"); template = null; nodes = null; } else alert("????????", "error"); } function Do_The_Toolbar_Thing (toolbar_name, nodes, pos, toolbars, com) { if (toolbar_name == undefined) toolbar_name = "sites"; var toolbar = new Toolbar(toolbar_name); toolbar.addButtons(pos, nodes); toolbar.save(); var toolbars = new Enumerator(toolbars); while (!toolbars.atEnd()) { if (toolbars.item() == toolbar_name) { state = toolbars.item().group; line = toolbars.item().line; break; } toolbars.moveNext(); } toolbars = null; com.RunCommand("Toolbar NAME=" + toolbar_name + " CLOSE"); DOpus.Delay(5); com.RunCommand("Toolbar NAME=" + toolbar_name + " LOCAL STATE=" + state + " LINE=" + line); toolbar = null; } function Add_Paths (dialog, paths, template, conf) { var name; var dom = new ActiveXObject("Msxml2.DOMDocument.6.0"); dom.async = false; var FSO = new ActiveXObject("Scripting.FileSystemObject"); var nodeList = dom.createDocumentFragment(); // alert("template:" + template, "info"); for (var i = 0; i < paths.length; i++) { paths(i) = (paths(i).slice(-1) == "\\") ? paths(i).slice(0, -1) : paths(i); if (DOpus.FSUtil.GetType(paths(i), "a") == "dir") { name = paths(i).substring(paths(i).lastIndexOf("\\")+1); try { if (FSO.GetDrive(paths(i)).VolumeName) name = FSO.GetDrive(paths(i)).VolumeName; } catch(e){} if (conf) { //Show a dialog if (dialog.Request("The button with the following info will be added:\nPath:" + paths(i) + "\nName:" + name + "\nAre you sure?.", "Yes|No", "Confirm button creation") == 0) continue; } try{ dom.loadXML(template.replace(/&dir&/g, paths(i)).replace(/&name&/g, name)); nodeList.appendChild(dom.documentElement); } catch(e) {alert(e.description, "error");} } }; name = null; dom = null; FSO = null; return nodeList; } function Add_with_GUI (paths, template, USEDISKLABELS) { var gui = new GUIWindow(); var dom = new ActiveXObject("Msxml2.DOMDocument.6.0"); var FSO = new ActiveXObject("Scripting.FileSystemObject"); var name; var nodeList = dom.createDocumentFragment(); var html = [ '', ' ', ' ', '
', '

Add Paths

' ]; for (var i = 0; i < paths.length; i++) { paths(i) = (paths(i).slice(-1) == "\\") ? paths(i).slice(0, -1) : paths(i); name = paths(i).substring(paths(i).lastIndexOf("\\")+1); try { if (FSO.GetDrive(paths(i)).VolumeName) name = FSO.GetDrive(paths(i)).VolumeName; } catch(e){} if (!FSO.FileExists(paths(i))) { html.push( '

', '', '

' ); } }; html.push( '

', '', '

', '', ''); gui.SetHTML(html.join("\r\n")); gui.SetTitle("Add Paths"); gui.Center(); gui.SetVisible(true); var control; while ((control = gui.GetValueById("control")) == "waiting") { gui.Focus(); DOpus.Delay(500); } gui.SetVisible(false); if (control == "done") { var form = gui.GetDocument().form1; var label, dn; for (var i = 0; i < form.length - 2; i = i + 3) { // DOpus.Output(form.elements[i].checked); // DOpus.Output('"' + form.elements[i+1].value + '"'); // DOpus.Output('"' + form.elements[i+2].value + '"'); if (form.elements[i].checked && DOpus.FSUtil.GetType(form.elements[i+2].value, "a") == "dir") { label = FSO.GetDrive((dn = FSO.GetDriveName(form.elements[i+2].value))).VolumeName; if (label && USEDISKLABELS) form.elements[i+2].value = form.elements[i+2].value.replace(dn, "{alias|$" + label + "}"); try{ dom.loadXML(template.replace(/&dir&/g, form.elements[i+2].value).replace(/&name&/g, form.elements[i+1].value)); nodeList.appendChild(dom.documentElement); } catch(e) {alert(e.description, "error");} } }; form = null; } gui.Quit(); dom = null; FSO = null; gui = null; return nodeList; } function getTemplate (temp) { if (DOpus.FSUtil.Exists(temp)) { var dom = new ActiveXObject("Msxml2.DOMDocument.6.0"); try { dom.load(temp); temp = dom.selectSingleNode("//button").xml; } catch(e){} dom = null; } else if (temp.toLowerCase() == "clip" && DOpus.GetClipFormat() == "text") temp = DOpus.GetClip(); else temp = template; return temp; } function Toolbar(name) { this.agregar = function(name, attrs) { var elem = this.xml.createElement(name); var attr; for (attr in attrs) { elem.setAttribute(attr, attrs[attr]); } this.xml.documentElement.appendChild(elem); return elem; }; this.addButton = function(pos, attrs, props, functions) { var attr, prop, temp; var button = this.xml.createElement("button"); for (attr in attrs) { button.setAttribute(attr, attrs[attr]); } if (typeof props == "object") { for (prop in props) { temp = this.xml.createElement(prop); temp.text = props[prop]; button.appendChild(temp); temp = null; } } if (functions != undefined) { var f = this.xml.createElement("function"); f.setAttribute("type", functions[0]); var i, inst; for (i = 1; i < functions.length; i++) { inst = this.xml.createElement("instruction"); inst.text = functions[i]; f.appendChild(inst); inst = null; }; button.appendChild(f); f = null; } if (typeof pos["ref"] == "number") pos["ref"] = this.getButton(pos["ref"]); if (pos["ref"] == null) pos["mode"] = "append"; switch(pos["mode"]) { case "replace" : this.buttons.replaceChild(button, pos["ref"]); break; case "within" : switch(pos[ref].getAttribute("type")) { case "menu" : case "menu_button" : case "three_button" : pos["ref"].appendChild(button); break; } break; case "append" : this.buttons.appendChild(button); break; default : return null; } return button; }; this.addButtons = function(pos, buttonList) { var ref; if (typeof pos != "number" || pos < 1) ref = this.getButtonByContent("field_type", "spacer"); else ref = this.getButton(pos); if (ref == undefined) this.buttons.appendChild(buttonList); else this.buttons.insertBefore(buttonList, ref); ref = null; }; this.getButtonByContent = function(attr, value) { return this.buttons.selectSingleNode("//button[@" + attr + "='" + value + "']"); }; this.getButton = function(pos) { return this.buttons.childNodes[pos-1]; }; this.save = function() { this.transform(); this.xml.save(this.file); }; this.transform = function() { var xsl = new ActiveXObject("Msxml2.DOMDocument.6.0"); var style = '\r\n'; style = style + '\r\n'; style = style + '\r\n'; style = style + '\r\n'; style = style + '\r\n'; style = style + '\r\n'; style = style + '\r\n'; style = style + '\r\n'; style = style + '\r\n'; style = style + '\r\n'; style = style + '\r\n'; xsl.loadXML(style); this.xml.transformNodeToObject(xsl,this.xml); xsl = style = null; }; this.file = DOpus.Aliases("buttons").path + "\\" + name + ".dop"; this.xml = new ActiveXObject("Msxml2.DOMDocument.6.0"); with (this.xml) { async = false; // validateOnParse = true; // resolveExternals = true; setProperty("SelectionLanguage", "XPath"); } this.buttons = null; //If the toolbar exists on disk, we load them if (DOpus.FSUtil.Exists(this.file)) { this.xml.load(this.file); this.buttons = this.xml.selectSingleNode("//buttons"); } //Otherwise create a default one else { DOpus.Output("Creating the toolbar " + name); var root = this.xml.createElement("toolbar"); root.setAttribute("version", "11.0"); this.xml.appendChild(root); root = null; // Add the wallpaper element this.agregar("wallpaper", { enabled: "no", inheritable: "yes", type: "toolbar" }); // Add the Buttons element this.buttons = this.agregar("buttons", { backcol: "none", display: "icon", textcol: "none", type: "menu"}); this.addButton( { ref: -1, mode: "append"}, { backcol: "none", display: "label", field_type: "spacer", textcol: "none", size: "full", separate: "yes"}, { label: "spacer", icon1: "#spacer"}, [ "normal", "Set SPACER"]); } } function GUIWindow() { this.objExplorer = new ActiveXObject("InternetExplorer.Application"); this.objExplorer.Navigate("about:blank"); this.width = (this.objExplorer.document.parentWindow.screen.availWidth * 60) / 100; this.height = this.objExplorer.document.parentWindow.screen.availHeight - 150; this.top = 100; this.left = 200; with(this.objExplorer) { // FullScreen = 1; ToolBar = 0; StatusBar = 0; Width = this.width; Height = this.height; Left = this.left; Top = this.top; Visible = 0; Resizable = 0; AlwaysRaised = 1; document.title = 'GUI with Jscript'; } this.Center = function() { var height = this.GetWindow().screen.availHeight; var width = this.GetWindow().screen.availWidth; wheight = this.GetDocument().form1.clientHeight + 70; this.SetSize(this.width, (wheight > height) ? this.height : wheight); this.MoveTo(width/2 - (this.GetDocument().documentElement.clientWidth/2),height/2 - (this.GetDocument().documentElement.clientHeight/2)); } this.MoveTo = function (x, y) { this.left = this.objExplorer.left = x; this.top = this.objExplorer.top = y; } this.SetTitle = function(title) { this.objExplorer.document.title = title; } this.GetDocument = function() { return this.objExplorer.document; } this.SetHTML = function(html) { this.objExplorer.document.write(html); } this.Quit = function() { try { this.objExplorer.quit(); this.objExplorer = null; } catch(e){} } this.SetSize = function(width,height) { this.width = this.objExplorer.Width = width; this.height = this.objExplorer.Height = height; } this.GetWindow = function() { return this.objExplorer.document.parentWindow; } this.ScrollTo = function(x,y) { objExplorer.document.parentWindow.scrollTo(x,y); } this.SetVisible = function(tf) { try { this.objExplorer.Visible=tf; } catch(e){} } this.Focus = function() { this.objExplorer.document.focus(); } this.GetValueById = function(id) { try { return this.objExplorer.document.getElementById(id).value; } catch (e) { return "exit"; } } this.SetValueById = function(id,value) { this.objExplorer.document.getElementById(id).value=value; } this.WaitOnId = function(id) { var elem = this.objExplorer.document.getElementById(id); var val= elem.value; while(elem.value == val) { DOpus.Delay(100); } return elem.value; } } function alert(message, icon, title) { dlg.message = message; if (title != undefined) dlg.title = title; if (/warning|error|info|question/.exec(icon) != null) dlg.icon = icon; dlg.Show(); }