/src/TranscriptStudio.mxml

http://transcriptstudio4isha.googlecode.com/ · Macromedia eXtensible Markup Language · 191 lines · 176 code · 15 blank · 0 comment · 0 complexity · e99baac297c7e824344ed0bf5521adf0 MD5 · raw file

  1. <!--
  2. Transcript Studio for Isha Foundation: An XML based application that allows users to define
  3. and store contextual metadata for contiguous sections within a text document.
  4. Copyright 2008 Mark Carter, Swami Kevala
  5. This file is part of Transcript Studio for Isha Foundation.
  6. Transcript Studio for Isha Foundation is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU General Public License as published by the Free Software
  8. Foundation, either version 3 of the License, or (at your option) any later version.
  9. Transcript Studio for Isha Foundation is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License along with
  13. Transcript Studio for Isha Foundation. If not, see http://www.gnu.org/licenses/.
  14. -->
  15. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:studioNS="org.ishafoundation.archives.transcript.components.studio.*" top="20" width="1000" height="600" layout="vertical" styleName="plain" backgroundColor="0x869CA7" xmlns:local="*" creationComplete="initApp()" pageTitle="Transcript Studio">
  16. <mx:Script>
  17. <![CDATA[
  18. import mx.managers.CursorManager;
  19. import org.ishafoundation.archives.transcript.components.generic.DatabasePopUp;
  20. import name.carter.mark.flex.util.remote.ClientManager;
  21. import name.carter.mark.flex.util.Utils;
  22. import org.ishafoundation.archives.transcript.db.DatabaseConstants;
  23. import org.ishafoundation.archives.transcript.components.studio.text.TranscriptTextArea;
  24. import org.ishafoundation.archives.transcript.components.studio.MainPanel;
  25. import org.ishafoundation.archives.transcript.components.generic.LoginPopUp;
  26. import mx.controls.Alert;
  27. import mx.events.FlexEvent;
  28. import mx.managers.PopUpManager;
  29. import org.ishafoundation.archives.transcript.db.DatabaseManagerUsingEXist;
  30. import mx.core.UIComponent;
  31. import org.ishafoundation.archives.transcript.components.generic.LoginPopUp;
  32. import name.carter.mark.flex.util.icon.IconUtils;
  33. import org.ishafoundation.archives.transcript.components.studio.text.TranscriptTextArea;
  34. import org.ishafoundation.archives.transcript.db.DatabaseManagerDemo;
  35. import org.ishafoundation.archives.transcript.db.DatabaseManager;
  36. private static const ICON_NAMES_TO_PRELOAD:Array = ["chant", "default", "joke", "music", "process", "question", "quote", "story", "topic"];
  37. private function preloadIcons(nextFunc:Function):void {
  38. trace("Preloading icons: " + ICON_NAMES_TO_PRELOAD);
  39. var count:int = 0;
  40. var completeFunc:Function = function():void {
  41. count++;
  42. if (count == ICON_NAMES_TO_PRELOAD.length) {
  43. trace("Finished preloading icons");
  44. nextFunc();
  45. }
  46. };
  47. for each (var iconName:String in ICON_NAMES_TO_PRELOAD) {
  48. var iconPath:String = Utils.getIconPath(iconName);
  49. IconUtils.preloadIcon(iconPath, completeFunc, function(msg:String):void {
  50. trace("Could not preload icon: " + msg);
  51. completeFunc();
  52. });
  53. }
  54. }
  55. private var databaseMgr:DatabaseManagerUsingEXist;
  56. private function initApp():void {
  57. addEventListener(Event.REMOVED_FROM_STAGE, function(evt:Event):void {
  58. trace("Removed from stage");
  59. });
  60. this.explicitWidth = NaN;
  61. this.explicitHeight = NaN;
  62. var thisHandle:Application = this;
  63. trace("Using default hostname");
  64. preloadIcons(function():void {
  65. TranscriptTextArea.ICONS_ENABLED = true;
  66. testConnection(function():void {
  67. var loginPopUp:LoginPopUp = PopUpManager.createPopUp(thisHandle, LoginPopUp, true) as LoginPopUp;
  68. PopUpManager.centerPopUp(loginPopUp);
  69. loginPopUp.loginButton.addEventListener(MouseEvent.CLICK, loginButtonClicked);
  70. loginPopUp.passwordTextInput.addEventListener(FlexEvent.ENTER, loginButtonClicked);
  71. //status = "Logging in...";
  72. });
  73. });
  74. }
  75. private function testConnection(successFunc:Function, databasePopUp:DatabasePopUp = null):void {
  76. var thisHandle:Application = this;
  77. CursorManager.setBusyCursor();
  78. ClientManager.testConnectionToURL(DatabaseConstants.EXIST_URL, function(response:Object):void {
  79. CursorManager.removeBusyCursor();
  80. if (databasePopUp != null) {
  81. PopUpManager.removePopUp(databasePopUp);
  82. }
  83. successFunc();
  84. }, function(evt:ErrorEvent):void {
  85. if (evt is SecurityErrorEvent && evt.text.indexOf("#2048") >= 0) {
  86. // this is an error caused by the sandbox security manager
  87. showSecurityAlert(evt.text);
  88. return;
  89. }
  90. CursorManager.removeBusyCursor();
  91. if (databasePopUp == null) {
  92. databasePopUp = PopUpManager.createPopUp(thisHandle, DatabasePopUp, true) as DatabasePopUp;
  93. PopUpManager.centerPopUp(databasePopUp);
  94. databasePopUp.okButton.addEventListener(MouseEvent.CLICK, function(evt:MouseEvent):void {
  95. DatabaseConstants.EXIST_URL = databasePopUp.urlTextInput.text;
  96. testConnection(successFunc, databasePopUp);
  97. });
  98. }
  99. else {
  100. Alert.show(DatabaseConstants.EXIST_URL, "Could not find database");
  101. }
  102. });
  103. }
  104. private function showIOAlert(text:String):void {
  105. this.enabled = false;
  106. Alert.show(text, "Could not find eXist DB");
  107. }
  108. private function showSecurityAlert(text:String):void {
  109. var startIndex:int = this.url.indexOf("file:///");
  110. this.enabled = false; // don't allow the user to do ANYTHING?
  111. var pathToAdd:String;
  112. if (startIndex >= 0) {
  113. pathToAdd = unescape(this.url.substring("file:///".length).replace("|", ":"));
  114. }
  115. else {
  116. pathToAdd = null;
  117. }
  118. var msg:String = "";
  119. if (pathToAdd != null) {
  120. msg = "Try this:\n\nRight click -> Settings... -> Advanced...\n\n(...takes you to browser...)\n\n-> Global Security Settings Panel\n\nAdd the following URL to \"Always trust files in these locations\":\n\n" + pathToAdd + "\n\nFinally, restart application\n\nOriginal Exception:\n\n";
  121. }
  122. msg += text;
  123. var al:Alert = Alert.show(msg, "Security Sandbox Violation");
  124. // important to move the Alert to the top left because the settings box also comes up in the middle (and its modal!)
  125. al.callLater(function():void {
  126. al.x = 20;
  127. al.y = 20;
  128. });
  129. }
  130. private function loginButtonClicked(event:Event):void {
  131. var loginPopUp:LoginPopUp = (event.currentTarget as UIComponent).document as LoginPopUp;
  132. if (!loginPopUp.loginButton.enabled) {
  133. // cheeky - the user hit enter in the password text input field when the button was disabled
  134. return;
  135. }
  136. var username:String = loginPopUp.usernameTextInput.text;
  137. var password:String = loginPopUp.passwordTextInput.text;
  138. databaseMgr = new DatabaseManagerUsingEXist(username, password, function():void {
  139. PopUpManager.removePopUp(loginPopUp);
  140. //status = "Login succeeded";
  141. // make sure the data collection has been created
  142. databaseMgr.query("xmldb:collection-exists($arg0)", [DatabaseConstants.DATA_COLLECTION_PATH], function(returnVal:Boolean):void {
  143. if (returnVal) {
  144. mainPanel.init(username, databaseMgr);
  145. mainPanel.visible = true;
  146. }
  147. else {
  148. Alert.show(DatabaseConstants.DATA_COLLECTION_PATH, "Could not find data collection");
  149. }
  150. },
  151. function(msg:String):void {
  152. Alert.show(msg);
  153. });
  154. }, loginFailed);
  155. }
  156. private function loginFailed(msg:String):void {
  157. //status = "Login failed";
  158. var index:int = msg.lastIndexOf("URL:") + 1;
  159. var url:String = index >= 0 ? msg.substr(index + 4) : msg;
  160. var s:String;
  161. if (msg.toLowerCase().indexOf("io error") >= 0) {
  162. s = "Could not connect to server: " + url;
  163. }
  164. else if (msg.toLowerCase().indexOf("version") >= 0) {
  165. s = msg;
  166. }
  167. else {
  168. s = "Incorrect username/password";
  169. }
  170. trace(msg);
  171. Alert.show(s, "Login failed");
  172. }
  173. ]]>
  174. </mx:Script>
  175. <studioNS:MainPanel id="mainPanel" width="100%" height="100%" verticalGap="0"/>
  176. </mx:Application>