PageRenderTime 56ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/opendap/src/main/java/opendap/servers/www/jscriptCore.tmpl

https://github.com/blazetopher/THREDDS
Go Template | 395 lines | 344 code | 51 blank | 0 comment | 0 complexity | d0d32c7b86c74177375248018298ee7a MD5 | raw file
  1. // -*- Java -*-
  2. /////////////////////////////////////////////////////////////////////////////
  3. // This file is part of the "Java-DAP" project, a Java implementation
  4. // of the OPeNDAP Data Access Protocol.
  5. //
  6. // Copyright (c) 2007 OPeNDAP, Inc.
  7. //
  8. // This library is free software; you can redistribute it and/or
  9. // modify it under the terms of the GNU Lesser General Public
  10. // License as published by the Free Software Foundation; either
  11. // version 2.1 of the License, or (at your option) any later version.
  12. //
  13. // This library is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. // Lesser General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Lesser General Public
  19. // License along with this library; if not, write to the Free Software
  20. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. //
  22. // You can contact OPeNDAP, Inc. at PO Box 112, Saunderstown, RI. 02874-0112.
  23. /////////////////////////////////////////////////////////////////////////////
  24. //
  25. // Authors:
  26. // jhrg,jimg James Gallagher (jgallagher@gso.uri.edu)
  27. var reflection_cgi = "http://unidata.ucar.edu/cgi-bin/dods/posturl.pl";
  28. // Event handlers for the disposition button.
  29. // The ascii_button handler sends data to a new window. The user can then
  30. // save the data to a file.
  31. function ascii_button() {
  32. var url = new String(document.forms[0].url.value);
  33. var url_parts = url.split("?");
  34. /* handle case where constraint is null. */
  35. if (url_parts[1] != null) {
  36. var ascii_url = url_parts[0] + ".ascii?" + url_parts[1];
  37. }
  38. else {
  39. var ascii_url = url_parts[0] + ".ascii?";
  40. }
  41. window.open(ascii_url, "ASCII_Data");
  42. }
  43. /* The binary_button handler loads the data to the current window. Since it
  44. is binary, Netscape will ask the user for a filename and save the data
  45. to that file. */
  46. function binary_button() {
  47. var url = new String(document.forms[0].url.value);
  48. var url_parts = url.split("?");
  49. /* handle case where constraint is null. */
  50. if (url_parts[1] != null) {
  51. var binary_url = url_parts[0] + ".dods?" + url_parts[1];
  52. }
  53. else {
  54. var binary_url = url_parts[0] + ".dods?";
  55. }
  56. window.location = binary_url;
  57. }
  58. /* Route the URL to Matlab, IDL, .... Users must add an entry into their mime
  59. types file (aka list of Netscape helper applications) so that the URL will
  60. be fedd into Matlab which must, in addition, be running loaddods.
  61. Note that reflection_cgi is a global JavaScript variable set at the
  62. begining of this `file'. */
  63. function program_button() {
  64. var program_url = new String(document.forms[0].url.value);
  65. /* Build a call to the reflector CGI. */
  66. var CGI = reflection_cgi + "?" + "url=" + program_url + "&disposition=matlab";
  67. window.location = CGI;
  68. }
  69. var help = 0; // Our friend, the help window.
  70. function help_button() {
  71. // Check the global to keep from opening the window again if it is
  72. // already visible. I think Netscape handles this but I know it will
  73. // write the contents over and over again. This preents that, too.
  74. // 10/8/99 jhrg
  75. if (help && !help.closed)
  76. return;
  77. // Resize on Netscape 4 is hosed. When enabled, if a user resizes then
  78. // the root window's document gets reloaded. This does not happen on IE5.
  79. // regardless, with scrollbars we don't absolutely need to be able to
  80. // resize. 10/8/99 jhrg
  81. help = window.open("", "help", "scrollbars,dependent,width=600,height=400");
  82. write_help_contents(help);
  83. }
  84. function write_help_contents() {
  85. help.document.writeln("<html><head><title> " +
  86. "Help for the DODS Dataset Access Form</title></head><body><form> " +
  87. "<center><h2>Help for the DODS Dataset Access Form</h2></center> " +
  88. "This form displays information from the dataset whose URL is shown in " +
  89. "the <em>DataURL</em> field. Each variable in this dataset is shown " +
  90. "below in the section labeled <em>Variables</em>. " +
  91. "<ul>" +
  92. "<li>To select a variable click on the checkbox to its left. " +
  93. "<li>To constrain a variable that you've selected, edit the information " +
  94. "that appears in the text boxes below the variable. " +
  95. "<li>To get ASCII or binary values for the variables you've selected, " +
  96. "click on the <em>Get ASCII</em> or <em>Get Binary</em> buttons. " +
  97. // "<li>To use the <em>Send to Program</em> feature you must install a web " +
  98. // "helper application that can route the DODS URL built by this form to a " +
  99. // "client. Look on the <a " +
  100. // "href=\"http://unidata.ucar.edu/packages/dods/\" target=\"DODS\"> " +
  101. // "DODS home page (http://unidata.ucar.edu/packages/dods/)</a> " +
  102. // "for a suitable client. " +
  103. // "</ul>" +
  104. "Note that the URL displayed in the <em>DataURL</em> field is updated " +
  105. "as you select and/or constrain variables. The URL in this field can be " +
  106. "cut and pasted in various DODS clients such as the Matlab and IDL " +
  107. "command extensions. See the <a " +
  108. "href=\"http://unidata.ucar.edu/packages/dods/\" target=\"DODS\"> " +
  109. "DODS home page</a> for " +
  110. "information about those clients. " +
  111. "<p><hr><p> " +
  112. "<center> " +
  113. "<input type=\"button\" value=\"Close\" onclick=\"self.close()\"> " +
  114. "</center></form></body></html>");
  115. }
  116. function open_dods_home() {
  117. window.open("http://unidata.ucar.edu/packages/dods/", "DODS_HOME_PAGE");
  118. }
  119. // Helper functions for the form.
  120. function describe_index() {
  121. defaultStatus = "Enter start, stride and stop for the array dimension.";
  122. }
  123. function describe_selection() {
  124. defaultStatus = "Enter a relational expression (e.g., <20).";
  125. }
  126. function describe_operator() {
  127. defaultStatus = "Choose a relational operator. Use - to enter a function name).";
  128. }
  129. function describe_projection() {
  130. defaultStatus = "Add this variable to the projection.";
  131. }
  132. ///////////////////////////////////////////////////////////
  133. // The dods_url object.
  134. ///////////////////////////////////////////////////////////
  135. // CTOR for dods_url
  136. // Create the DODS URL object.
  137. function dods_url(base_url) {
  138. this.url = base_url;
  139. this.projection = "";
  140. this.selection = "";
  141. this.num_dods_vars = 0;
  142. this.dods_vars = new Array();
  143. this.build_constraint = build_constraint;
  144. this.add_dods_var = add_dods_var;
  145. this.update_url = update_url;
  146. }
  147. // Method of dods_url
  148. // Add the projection and selection to the displayed URL.
  149. function update_url() {
  150. this.build_constraint();
  151. var url_text = this.url;
  152. // Only add the projection & selection (and ?) if there really are
  153. // constraints!
  154. if (this.projection.length + this.selection.length > 0)
  155. url_text += "?" + this.projection + this.selection;
  156. document.forms[0].url.value = url_text;
  157. }
  158. // Method of dods_url
  159. // Scan all the form elements and pick out the various pieces of constraint
  160. // information. Add these to the dods_url instance.
  161. function build_constraint() {
  162. var p = "";
  163. var s = "";
  164. for (var i = 0; i < this.num_dods_vars; ++i) {
  165. if (this.dods_vars[i].is_projected == 1) {
  166. // The comma is a clause separator.
  167. if (p.length > 0)
  168. p += ",";
  169. p += this.dods_vars[i].get_projection();
  170. }
  171. var temp_s = this.dods_vars[i].get_selection();
  172. if (temp_s.length > 0)
  173. s += "&" + temp_s; // The ampersand is a prefix to the clause.
  174. }
  175. this.projection = p;
  176. this.selection = s;
  177. }
  178. // Method of dods_url
  179. // Add the variable to the dods_var array of dods_vars. The var_index is the
  180. // number of *this particular* variable in the dataset, zero-based.
  181. function add_dods_var(dods_var) {
  182. this.dods_vars[this.num_dods_vars] = dods_var;
  183. this.num_dods_vars++;
  184. }
  185. /////////////////////////////////////////////////////////////////
  186. // dods_var
  187. /////////////////////////////////////////////////////////////////
  188. // CTOR for dods_var
  189. // name: the name of the variable from DODS' perspective.
  190. // js_var_name: the name of the variable within the form.
  191. // is_array: 1 if this is an array, 0 otherwise.
  192. function dods_var(name, js_var_name, is_array) {
  193. // Common members
  194. this.name = name;
  195. this.js_var_name = js_var_name;
  196. this.is_projected = 0;
  197. if (is_array > 0) {
  198. this.is_array = 1;
  199. this.num_dims = 0; // Holds the number of dimensions
  200. this.dims = new Array(); // Holds the length of the dimensions
  201. this.add_dim = add_dim;
  202. this.display_indices = display_indices;
  203. this.erase_indices = erase_indices;
  204. }
  205. else
  206. this.is_array = 0;
  207. this.handle_projection_change = handle_projection_change;
  208. this.get_projection = get_projection;
  209. this.get_selection = get_selection;
  210. }
  211. // Method of dods_var
  212. // Add a dimension to a DODS Array object.
  213. function add_dim(dim_size) {
  214. this.dims[this.num_dims] = dim_size;
  215. this.num_dims++;
  216. }
  217. // Method of dods_var
  218. // Add the array indices to the text widgets associated with this DODS
  219. // array object. The text widgets are names <var_name>_0, <var_name>_1, ...
  220. // <var_name>_n for an array with size N+1.
  221. function display_indices() {
  222. for (var i = 0; i < this.num_dims; ++i) {
  223. var end_index = this.dims[i]-1;
  224. var s = "0:1:" + end_index.toString();
  225. var text_widget = "document.forms[0]." + this.js_var_name + "_" + i.toString();
  226. eval(text_widget).value = s;
  227. }
  228. }
  229. // Method of dods_var
  230. // Use this to remove index information from a DODS array object.
  231. function erase_indices() {
  232. for (var i = 0; i < this.num_dims; ++i) {
  233. var text_widget = "document.forms[0]." + this.js_var_name + "_" + i.toString();
  234. eval(text_widget).value = "";
  235. }
  236. }
  237. // Method of dods_var
  238. function handle_projection_change(check_box) {
  239. if (check_box.checked) {
  240. this.is_projected = 1;
  241. if (this.is_array == 1)
  242. this.display_indices();
  243. }
  244. else {
  245. this.is_projected = 0;
  246. if (this.is_array == 1)
  247. this.erase_indices();
  248. }
  249. DODS_URL.update_url();
  250. }
  251. // Method of dods_var
  252. // Get the projection sub-expression for this variable.
  253. function get_projection() {
  254. var p = "";
  255. if (this.is_array == 1) {
  256. p = this.name; // ***
  257. for (var i = 0; i < this.num_dims; ++i) {
  258. var text_widget = "document.forms[0]." + this.js_var_name + "_" + i.toString();
  259. p += "[" + eval(text_widget).value + "]";
  260. }
  261. }
  262. else {
  263. p = this.name; // ***
  264. }
  265. return p;
  266. }
  267. // Method of dods_var
  268. // Get the selection (which is null for arrays).
  269. function get_selection() {
  270. var s = "";
  271. if (this.is_array == 1) {
  272. return s;
  273. }
  274. else {
  275. var text_widget = "document.forms[0]." + this.js_var_name + "_selection";
  276. if (eval(text_widget).value != "") {
  277. var oper_widget_name = "document.forms[0]." + this.js_var_name + "_operator";
  278. var oper_widget = eval(oper_widget_name);
  279. var operator = oper_widget.options[oper_widget.selectedIndex].value;
  280. // If the operator is `-' then don't prepend the variable name!
  281. // This provides a way for users to enter function names as
  282. // selection clauses.
  283. if (operator == "-")
  284. s = eval(text_widget).value;
  285. else
  286. s = this.name + operator + eval(text_widget).value; // ***
  287. }
  288. }
  289. return s;
  290. }
  291. // $Log: jscriptCore.tmpl,v $
  292. // Revision 1.1 2003/08/12 23:51:27 ndp
  293. // Mass check in to begin Java-OPeNDAP development work
  294. //
  295. // Revision 1.1 2002/03/26 19:57:17 ndp
  296. // *** empty log message ***
  297. //
  298. // Revision 1.4 2001/09/17 23:05:53 ndp
  299. // *** empty log message ***
  300. //
  301. // Revision 1.1.2.3 2001/09/10 21:48:07 jimg
  302. // Removed the `Send to Program' button and its help text.
  303. //
  304. // Revision 1.1.2.2 2001/09/10 19:32:28 jimg
  305. // Fixed two problems: 1) Variable names in the JavaScript code sometimes
  306. // contained spaces since they were made using the dataset's variable name.
  307. // The names are now filtered through id2www and esc2underscore. 2) The CE
  308. // sometimes contained spaces, again, because dataset variable names were
  309. // used to build the CE. I filtered the names with id2www_ce before passing
  310. // them to the JavaScript code.
  311. //
  312. // Revision 1.1.2.1 2001/01/26 04:01:13 jimg
  313. // Added
  314. //
  315. // Revision 1.5 2000/11/09 21:04:37 jimg
  316. // Merged changes from release-3-1. There was a goof and a bunch of the
  317. // changes never made it to the branch. I merged the entire branch.
  318. // There maybe problems still...
  319. //
  320. // Revision 1.4 2000/10/03 20:07:21 jimg
  321. // Moved Logs to the end of each file.
  322. //
  323. // Revision 1.3 1999/05/18 20:08:18 jimg
  324. // Fixed massive problems introduced by the String to string changes.
  325. //
  326. // Revision 1.2 2000/11/09 21:04:37 jimg
  327. // Merged changes from release-3-1. There was a goof and a bunch of the
  328. // changes never made it to the branch. I merged the entire branch.
  329. // There maybe problems still...
  330. //
  331. // Revision 1.1.2.3 1999/10/13 17:02:55 jimg
  332. // Changed location of posturl.pl.
  333. //
  334. // Revision 1.1.2.2 1999/10/11 17:57:32 jimg
  335. // Fixed a bug which showed up in IE 5. Objects in IE 5 cannot use eval() to
  336. // name a field and access a property of that field in the same statement.
  337. // Instead, the use of eval to name a field and the access to that (new)
  338. // field must be broken up. I think this is the case because IE 5's parser
  339. // thinks `eval' is, in this situation, an object property. Of course,
  340. // there's no eval property per se, so script execution halts. See the use of
  341. // the document.forms[0].<text_widget> stuff in the method display_indices().
  342. //
  343. // Revision 1.1.2.1 1999/10/09 00:30:36 jimg
  344. // Created.