]> git.evergreen-ils.org Git - Evergreen.git/blob - Evergreen/staff_client/install.js
tweaking the staff client layout and moving it slowly into the public cvs repository...
[Evergreen.git] / Evergreen / staff_client / install.js
1 // XpiInstaller
2 // By Pike (Heavily inspired by code from Henrik Gemal and Stephen Clavering)
3 // Modified by Jason for Evergreen
4
5 var XpiInstaller = {
6
7         // --- Editable items begin ---
8         extFullName: 'Evergreen Staff Client Demo', // The name displayed to the user (don't include the version)
9         extShortName: 'evergreen', // The leafname of the JAR file (without the .jar part)
10         extVersion: '0.0.4',
11         extAuthor: 'GPLS',
12         extLocaleNames: ['en-US'], //null, // e.g. ['en-US', 'en-GB']
13         extSkinNames: null, // e.g. ['classic', 'modern']
14         extPostInstallMessage: 'Success! Please restart your browser to finish the installation.', // Set to null for no post-install message
15         // --- Editable items end ---
16
17         profileInstall: true,
18         silentInstall: false,
19
20         install: function()
21         {
22                 var jarName = this.extShortName + '.jar';
23                 var profileDir = Install.getFolder('Profile', 'chrome');
24
25                 // Parse HTTP arguments
26                 this.parseArguments();
27
28                 // Check if extension is already installed in profile
29                 if (File.exists(Install.getFolder(profileDir, jarName)))
30                 {
31                         if (!this.silentInstall)
32                         {
33                                 Install.alert('Updating existing Profile install of ' + this.extFullName + ' to version ' + this.extVersion + '.');
34                         }
35                         this.profileInstall = true;
36                 }
37                 else if (!this.silentInstall)
38                 {
39                         // Ask user for install location, profile or browser dir?
40                         this.profileInstall = Install.confirm('Install ' + this.extFullName + ' ' + this.extVersion + ' to your Profile directory (OK) or your Browser directory (Cancel)?');
41                 }
42
43                 // Init install
44                 var dispName = this.extFullName + ' ' + this.extVersion;
45                 var regName = '/' + this.extAuthor + '/' + this.extShortName;
46                 Install.initInstall(dispName, regName, this.extVersion);
47
48                 // Find directory to install into
49                 var installPath;
50                 if (this.profileInstall) installPath = profileDir;
51                 else installPath = Install.getFolder('chrome');
52
53                 // Add JAR file
54                 Install.addFile(null, 'chrome/' + jarName, installPath, null);
55
56                 // Register chrome
57                 var jarPath = Install.getFolder(installPath, jarName);
58                 var installType = this.profileInstall ? Install.PROFILE_CHROME : Install.DELAYED_CHROME;
59
60                 // Register content
61                 Install.registerChrome(Install.CONTENT | installType, jarPath, 'content/' + this.extShortName + '/');
62
63                 // Register locales
64                 for (var locale in this.extLocaleNames)
65                 {
66                         var regPath = 'locale/' + this.extLocaleNames[locale] + '/' + this.extShortName + '/';
67                         Install.registerChrome(Install.LOCALE | installType, jarPath, regPath);
68                 }
69
70                 // Register skins
71                 for (var skin in this.extSkinNames)
72                 {
73                         var regPath = 'skin/' + this.extSkinNames[skin] + '/' + this.extShortName + '/';
74                         Install.registerChrome(Install.SKIN | installType, jarPath, regPath);
75                 }
76
77                 // Perform install
78                 var err = Install.performInstall();
79                 if (err == Install.SUCCESS || err == Install.REBOOT_NEEDED)
80                 {
81                         if (!this.silentInstall && this.extPostInstallMessage)
82                         {
83                                 Install.alert(this.extPostInstallMessage);
84                         }
85                 }
86                 else
87                 {
88                         this.handleError(err);
89                         return;
90                 }
91         },
92
93         parseArguments: function()
94         {
95                 // Can't use string handling in install, so use if statement instead
96                 var args = Install.arguments;
97                 if (args == 'p=0')
98                 {
99                         this.profileInstall = false;
100                         this.silentInstall = true;
101                 }
102                 else if (args == 'p=1')
103                 {
104                         this.profileInstall = true;
105                         this.silentInstall = true;
106                 }
107         },
108
109         handleError: function(err)
110         {
111                 if (!this.silentInstall)
112                 {
113                         Install.alert('Error: Could not install ' + this.extFullName + ' ' + this.extVersion + ' (Error code: ' + err + ')');
114                 }
115                 Install.cancelInstall(err);
116         }
117 };
118
119 XpiInstaller.install();