1 Components.utils.import("resource://gre/modules/XPCOMUtils.jsm");
\r
3 // This component exists to handle custom command line options
\r
4 // First up, some useful constants
\r
6 // Standalone interface information
\r
7 const XUL_STANDALONE = "chrome://open_ils_staff_client/content/circ/offline.xul";
\r
8 const WINDOW_STANDALONE = "eg_offline"
\r
9 // Main (login) window information
\r
10 const XUL_MAIN = "chrome://open_ils_staff_client/content/main/main.xul";
\r
11 const WINDOW_MAIN = "eg_main"
\r
13 // Useful utility functions
\r
16 * Opens a chrome window.
\r
17 * @param aChromeURISpec a string specifying the URI of the window to open.
\r
18 * @param aArgument an argument to pass to the window (may be null)
\r
20 function findOrOpenWindow(aWindowType, aChromeURISpec, aName, aArgument, aLoginInfo)
\r
22 var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
\r
23 .getService(Components.interfaces.nsIWindowMediator);
\r
24 var targetWindow = wm.getMostRecentWindow(aWindowType);
\r
25 if (targetWindow != null) {
\r
26 var noFocus = false;
\r
27 if(typeof targetWindow.new_tabs == 'function' && aArgument != null) {
\r
28 targetWindow.new_tabs(aArgument);
\r
31 if(typeof targetWindow.auto_login == 'function' && aLoginInfo != null) {
\r
32 targetWindow.auto_login(aLoginInfo);
\r
36 targetWindow.focus();
\r
41 if (aArgument != null && aArgument.length != 0 || aLoginInfo != null)
\r
43 params = { "openTabs" : aArgument, "loginInfo" : aLoginInfo };
\r
44 params.wrappedJSObject = params;
\r
46 var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"]
\r
47 .getService(Components.interfaces.nsIWindowWatcher);
\r
48 ww.openWindow(null, aChromeURISpec, aName, "chrome,resizable,dialog=no", params);
\r
52 function oilsCommandLineHandler() {}
\r
53 oilsCommandLineHandler.prototype = {
\r
54 classDescription: "OpenILS Command Line Handler",
\r
55 classID: Components.ID("{7e608198-7355-483a-a85a-20322e4ef91a}"),
\r
56 contractID: "@mozilla.org/commandlinehandler/general-startup;1?type=egcli",
\r
57 _xpcom_categories: [{
\r
58 category: "command-line-handler",
\r
61 QueryInterface: XPCOMUtils.generateQI([Components.interfaces.nsICommandLineHandler]),
\r
62 handle : function clh_handle(cmdLine) {
\r
63 // Each of these options is used for opening a new tab, either on login or remote send.
\r
64 // XULRunner does some sanitize to turn /ilsblah into -ilsblah, for example.
\r
65 // In addition to the ones here:
\r
66 // -ilslogin, -ilsoffline, -ilsstandalone, -ilshost, -ilsuser, and -ilspassword
\r
67 // are defined below.
\r
69 // With the exception of 'new', 'tab', and 'init', the value is checked for in urls in main.js.
\r
71 // NOTE: The option itself should be all lowercase (we .toLowerCase below)
\r
73 '-ilscheckin' : 'XUL_CHECKIN',
\r
74 '-ilscheckout' : 'XUL_PATRON_BARCODE_ENTRY',
\r
75 '-ilsnew' : 'new', // 'new' is a special keyword for opening a new window
\r
76 '-ilstab' : 'tab', // 'tab' is a special keyword for opening a new tab with the default content
\r
77 '-ilsnew_default' : 'init', // 'init' is a special keyword for opening a new window with an initial default tab
\r
80 var inParams = new Array();
\r
82 var loginInfoProvided = false;
\r
84 while (position < cmdLine.length) {
\r
85 var arg = cmdLine.getArgument(position).toLowerCase();
\r
86 if (options[arg] != undefined) {
\r
87 inParams.push(options[arg]);
\r
88 cmdLine.removeArguments(position,position);
\r
91 if (arg == '-ilsurl' && cmdLine.length > position) {
\r
92 inParams.push(cmdLine.getArgument(position + 1));
\r
93 cmdLine.removeArguments(position, position + 1);
\r
96 if (arg == '-ilshost' && cmdLine.length > position) {
\r
97 loginInfo.host = cmdLine.getArgument(position + 1);
\r
98 cmdLine.removeArguments(position, position + 1);
\r
99 loginInfoProvided = true;
\r
102 if (arg == '-ilsuser' && cmdLine.length > position) {
\r
103 loginInfo.user = cmdLine.getArgument(position + 1);
\r
104 cmdLine.removeArguments(position, position + 1);
\r
105 loginInfoProvided = true;
\r
108 if (arg == '-ilspassword' && cmdLine.length > position) {
\r
109 loginInfo.passwd = cmdLine.getArgument(position + 1);
\r
110 cmdLine.removeArguments(position, position + 1);
\r
111 loginInfoProvided = true;
\r
114 position=position + 1;
\r
117 if (cmdLine.handleFlag("ILSlogin", false) || inParams.length > 0 || loginInfoProvided) {
\r
118 findOrOpenWindow(WINDOW_MAIN, XUL_MAIN, '_blank', inParams, loginInfoProvided ? loginInfo : null);
\r
119 cmdLine.preventDefault = true;
\r
122 if (cmdLine.handleFlag("ILSoffline", false) || cmdLine.handleFlag("ILSstandalone", false)) {
\r
123 findOrOpenWindow(WINDOW_STANDALONE, XUL_STANDALONE, 'Offline', null, null);
\r
124 cmdLine.preventDefault = true;
\r
129 // Flag descriptions start on char 24
\r
130 // 72 char wrap on lines, embedded newlines
\r
131 // End with a newline
\r
132 helpInfo : " -ILScheckin Open an Evergreen checkin tab\n" +
\r
133 " -ILScheckout Open an Evergreen checkout tab\n" +
\r
134 " -ILSnew Open a new Evergreen 'menu' window\n" +
\r
135 " -ILSnew_default Open a new Evergreen 'menu' window,\n" +
\r
136 " with a 'default' tab\n" +
\r
137 " -ILStab Open a 'default' tab alone\n" +
\r
138 " -ILSurl <url> Open the specified url in an Evergreen tab\n" +
\r
139 " -ILShost Default hostname for login\n" +
\r
140 " -ILSuser Default username for login\n" +
\r
141 " -ILSpassword Default password for login\n" +
\r
142 " The above three, if all specified, trigger an automatic login attempt\n" +
\r
143 " The above nine imply -ILSlogin\n" +
\r
144 " -ILSlogin Open the Evergreen Login window\n" +
\r
145 " -ILSstandalone Open the Evergreen Standalone interface\n" +
\r
146 " -ILSoffline Alias for -ILSstandalone\n",
\r
149 if (XPCOMUtils.generateNSGetFactory)
\r
150 var NSGetFactory = XPCOMUtils.generateNSGetFactory([oilsCommandLineHandler]);
\r
152 var NSGetModule = XPCOMUtils.generateNSGetModule([oilsCommandLineHandler]);
\r