PageRenderTime 25ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/ReferenceCode/phpmyadmin/js/common.js

https://gitlab.com/ctheilman92/Aging-In-Place
JavaScript | 288 lines | 156 code | 4 blank | 128 comment | 39 complexity | b62846639e9149de348b1505241ac8ea MD5 | raw file
  1. /* vim: set expandtab sw=4 ts=4 sts=4: */
  2. /**
  3. * Functionality for communicating with the querywindow
  4. */
  5. $(function () {
  6. /**
  7. * Event handler for click on the open query window link
  8. * in the top menu of the navigation panel
  9. */
  10. $('#pma_open_querywindow').click(function (event) {
  11. event.preventDefault();
  12. PMA_querywindow.focus();
  13. });
  14. });
  15. /**
  16. * Holds common parameters such as server, db, table, etc
  17. *
  18. * The content for this is normally loaded from Header.class.php or
  19. * Response.class.php and executed by ajax.js
  20. */
  21. var PMA_commonParams = (function () {
  22. /**
  23. * @var hash params An associative array of key value pairs
  24. * @access private
  25. */
  26. var params = {};
  27. // The returned object is the public part of the module
  28. return {
  29. /**
  30. * Saves all the key value pair that
  31. * are provided in the input array
  32. *
  33. * @param hash obj The input array
  34. *
  35. * @return void
  36. */
  37. setAll: function (obj) {
  38. var reload = false;
  39. for (var i in obj) {
  40. if (params[i] !== undefined && params[i] !== obj[i]) {
  41. reload = true;
  42. }
  43. params[i] = obj[i];
  44. }
  45. if (reload) {
  46. PMA_querywindow.refresh();
  47. }
  48. },
  49. /**
  50. * Retrieves a value given its key
  51. * Returns empty string for undefined values
  52. *
  53. * @param string name The key
  54. *
  55. * @return string
  56. */
  57. get: function (name) {
  58. return params[name] || '';
  59. },
  60. /**
  61. * Saves a single key value pair
  62. *
  63. * @param string name The key
  64. * @param string value The value
  65. *
  66. * @return self For chainability
  67. */
  68. set: function (name, value) {
  69. if (params[name] !== undefined && params[name] !== value) {
  70. PMA_querywindow.refresh();
  71. PMA_reloadNavigation();
  72. }
  73. params[name] = value;
  74. return this;
  75. },
  76. /**
  77. * Returns the url query string using the saved parameters
  78. *
  79. * @return string
  80. */
  81. getUrlQuery: function () {
  82. return $.sprintf(
  83. '?%s&server=%s&db=%s&table=%s',
  84. this.get('common_query'),
  85. encodeURIComponent(this.get('server')),
  86. encodeURIComponent(this.get('db')),
  87. encodeURIComponent(this.get('table'))
  88. );
  89. }
  90. };
  91. })();
  92. /**
  93. * Holds common parameters such as server, db, table, etc
  94. *
  95. * The content for this is normally loaded from Header.class.php or
  96. * Response.class.php and executed by ajax.js
  97. */
  98. var PMA_commonActions = {
  99. /**
  100. * Saves the database name when it's changed
  101. * and reloads the query window, if necessary
  102. *
  103. * @param string new_db The name of the new database
  104. *
  105. * @return void
  106. */
  107. setDb: function (new_db) {
  108. if (new_db != PMA_commonParams.get('db')) {
  109. PMA_commonParams.set('db', new_db);
  110. PMA_querywindow.refresh();
  111. }
  112. },
  113. /**
  114. * Opens a database in the main part of the page
  115. *
  116. * @param string new_db The name of the new database
  117. *
  118. * @return void
  119. */
  120. openDb: function (new_db) {
  121. PMA_commonParams
  122. .set('db', new_db)
  123. .set('table', '');
  124. PMA_querywindow.refresh();
  125. this.refreshMain(
  126. PMA_commonParams.get('opendb_url')
  127. );
  128. },
  129. /**
  130. * Refreshes the main frame
  131. *
  132. * @param mixed url Undefined to refresh to the same page
  133. * String to go to a different page, e.g: 'index.php'
  134. *
  135. * @return void
  136. */
  137. refreshMain: function (url, callback) {
  138. if (! url) {
  139. url = $('#selflink a').attr('href');
  140. url = url.substring(0, url.indexOf('?'));
  141. }
  142. url += PMA_commonParams.getUrlQuery();
  143. $('<a />', {href: url})
  144. .appendTo('body')
  145. .click()
  146. .remove();
  147. AJAX._callback = callback;
  148. }
  149. };
  150. /**
  151. * Common functions used for communicating with the querywindow
  152. */
  153. var PMA_querywindow = (function ($, window) {
  154. /**
  155. * @var Object querywindow Reference to the window
  156. * object of the querywindow
  157. * @access private
  158. */
  159. var querywindow = {};
  160. /**
  161. * @var string queryToLoad Stores the SQL query that is to be displayed
  162. * in the querywindow when it is ready
  163. * @access private
  164. */
  165. var queryToLoad = '';
  166. // The returned object is the public part of the module
  167. return {
  168. /**
  169. * Opens the query window
  170. *
  171. * @param mixed url Undefined to open the default page
  172. * String to go to a different
  173. *
  174. * @return void
  175. */
  176. open: function (url, sql_query) {
  177. if (! url) {
  178. url = 'querywindow.php' + PMA_commonParams.getUrlQuery();
  179. }
  180. if (sql_query) {
  181. url += '&sql_query=' + encodeURIComponent(sql_query);
  182. }
  183. if (! querywindow.closed && querywindow.location) {
  184. var href = querywindow.location.href;
  185. if (href != url
  186. && href != PMA_commonParams.get('pma_absolute_uri') + url
  187. ) {
  188. if (PMA_commonParams.get('safari_browser')) {
  189. querywindow.location.href = targeturl;
  190. } else {
  191. querywindow.location.replace(targeturl);
  192. }
  193. querywindow.focus();
  194. }
  195. } else {
  196. querywindow = window.open(
  197. url + '&init=1',
  198. '',
  199. 'toolbar=0,location=0,directories=0,status=1,'
  200. + 'menubar=0,scrollbars=yes,resizable=yes,'
  201. + 'width=' + PMA_commonParams.get('querywindow_width') + ','
  202. + 'height=' + PMA_commonParams.get('querywindow_height')
  203. );
  204. }
  205. if (! querywindow.opener) {
  206. querywindow.opener = window.window;
  207. }
  208. if (window.focus) {
  209. querywindow.focus();
  210. }
  211. },
  212. /**
  213. * Opens, if necessary, focuses the query window
  214. * and displays an SQL query.
  215. *
  216. * @param string sql_query The SQL query to display in
  217. * the query window
  218. *
  219. * @return void
  220. */
  221. focus: function (sql_query) {
  222. if (! querywindow || querywindow.closed || ! querywindow.location) {
  223. // we need first to open the window and cannot pass the query with it
  224. // as we dont know if the query exceeds max url length
  225. queryToLoad = sql_query;
  226. this.open(false, sql_query);
  227. } else {
  228. //var querywindow = querywindow;
  229. var hiddenqueryform = querywindow
  230. .document
  231. .getElementById('hiddenqueryform');
  232. if (hiddenqueryform.querydisplay_tab != 'sql' ) {
  233. hiddenqueryform.querydisplay_tab.value = "sql";
  234. hiddenqueryform.sql_query.value = sql_query;
  235. $(hiddenqueryform).addClass('disableAjax');
  236. hiddenqueryform.submit();
  237. querywindow.focus();
  238. } else {
  239. querywindow.focus();
  240. }
  241. }
  242. },
  243. /**
  244. * Refreshes the query window given a url
  245. *
  246. * @param string url Where to go to
  247. *
  248. * @return void
  249. */
  250. refresh: function (url) {
  251. if (! querywindow.closed && querywindow.location) {
  252. var $form = $(querywindow.document).find('#sqlqueryform');
  253. if ($form.find('#checkbox_lock:checked').length == 0) {
  254. PMA_querywindow.open(url);
  255. }
  256. }
  257. },
  258. /**
  259. * Reloads the query window given the details
  260. * of a db, a table and an sql_query
  261. *
  262. * @param string db The name of the database
  263. * @param string table The name of the table
  264. * @param string sql_query The SQL query to be displayed
  265. *
  266. * @return void
  267. */
  268. reload: function (db, table, sql_query) {
  269. if (! querywindow.closed && querywindow.location) {
  270. var $form = $(querywindow.document).find('#sqlqueryform');
  271. if ($form.find('#checkbox_lock:checked').length == 0) {
  272. var $hiddenform = $(querywindow.document)
  273. .find('#hiddenqueryform');
  274. $hiddenform.find('input[name=db]').val(db);
  275. $hiddenform.find('input[name=table]').val(table);
  276. if (sql_query) {
  277. $hiddenform.find('input[name=sql_query]').val(sql_query);
  278. }
  279. $hiddenform.addClass('disableAjax').submit();
  280. }
  281. }
  282. }
  283. };
  284. })(jQuery, window);