instances.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. function addInstance() {
  2. try {
  3. var query = "backend.php?op=pluginhandler&plugin=instances&method=addInstance";
  4. if (dijit.byId("instanceAddDlg"))
  5. dijit.byId("instanceAddDlg").destroyRecursive();
  6. dialog = new dijit.Dialog({
  7. id: "instanceAddDlg",
  8. title: __("Link Instance"),
  9. style: "width: 600px",
  10. regenKey: function() {
  11. new Ajax.Request("backend.php", {
  12. parameters: "op=pluginhandler&plugin=instances&method=genHash",
  13. onComplete: function(transport) {
  14. var reply = JSON.parse(transport.responseText);
  15. if (reply)
  16. dijit.byId('instance_add_key').attr('value', reply.hash);
  17. } });
  18. },
  19. execute: function() {
  20. if (this.validate()) {
  21. console.warn(dojo.objectToQuery(this.attr('value')));
  22. notify_progress('Saving data...', true);
  23. new Ajax.Request("backend.php", {
  24. parameters: dojo.objectToQuery(this.attr('value')),
  25. onComplete: function(transport) {
  26. dialog.hide();
  27. notify('');
  28. updateInstanceList();
  29. } });
  30. }
  31. },
  32. href: query,
  33. });
  34. dialog.show();
  35. } catch (e) {
  36. exception_error("addInstance", e);
  37. }
  38. }
  39. // *** INS ***
  40. function updateInstanceList(sort_key) {
  41. new Ajax.Request("backend.php", {
  42. parameters: "op=pluginhandler&plugin=instances&sort=" + param_escape(sort_key),
  43. onComplete: function(transport) {
  44. dijit.byId('instanceConfigTab').attr('content', transport.responseText);
  45. selectTab("instanceConfig", true);
  46. notify("");
  47. } });
  48. }
  49. function editInstance(id, event) {
  50. try {
  51. if (!event || !event.ctrlKey) {
  52. selectTableRows('prefInstanceList', 'none');
  53. selectTableRowById('LIRR-'+id, 'LICHK-'+id, true);
  54. var query = "backend.php?op=pluginhandler&plugin=instances&method=edit&id=" +
  55. param_escape(id);
  56. if (dijit.byId("instanceEditDlg"))
  57. dijit.byId("instanceEditDlg").destroyRecursive();
  58. dialog = new dijit.Dialog({
  59. id: "instanceEditDlg",
  60. title: __("Edit Instance"),
  61. style: "width: 600px",
  62. regenKey: function() {
  63. new Ajax.Request("backend.php", {
  64. parameters: "op=pluginhandler&plugin=instances&method=genHash",
  65. onComplete: function(transport) {
  66. var reply = JSON.parse(transport.responseText);
  67. if (reply)
  68. dijit.byId('instance_edit_key').attr('value', reply.hash);
  69. } });
  70. },
  71. execute: function() {
  72. if (this.validate()) {
  73. // console.warn(dojo.objectToQuery(this.attr('value')));
  74. notify_progress('Saving data...', true);
  75. new Ajax.Request("backend.php", {
  76. parameters: dojo.objectToQuery(this.attr('value')),
  77. onComplete: function(transport) {
  78. dialog.hide();
  79. notify('');
  80. updateInstanceList();
  81. } });
  82. }
  83. },
  84. href: query,
  85. });
  86. dialog.show();
  87. } else if (event.ctrlKey) {
  88. var cb = $('LICHK-' + id);
  89. cb.checked = !cb.checked;
  90. toggleSelectRow(cb);
  91. }
  92. } catch (e) {
  93. exception_error("editInstance", e);
  94. }
  95. }
  96. function removeSelectedInstances() {
  97. try {
  98. var sel_rows = getSelectedInstances();
  99. if (sel_rows.length > 0) {
  100. var ok = confirm(__("Remove selected instances?"));
  101. if (ok) {
  102. notify_progress("Removing selected instances...");
  103. var query = "op=pluginhandler&plugin=instances&method=remove&ids="+
  104. param_escape(sel_rows.toString());
  105. new Ajax.Request("backend.php", {
  106. parameters: query,
  107. onComplete: function(transport) {
  108. notify('');
  109. updateInstanceList();
  110. } });
  111. }
  112. } else {
  113. alert(__("No instances are selected."));
  114. }
  115. } catch (e) {
  116. exception_error("removeInstance", e);
  117. }
  118. }
  119. function editSelectedInstance() {
  120. var rows = getSelectedInstances();
  121. if (rows.length == 0) {
  122. alert(__("No instances are selected."));
  123. return;
  124. }
  125. if (rows.length > 1) {
  126. alert(__("Please select only one instance."));
  127. return;
  128. }
  129. notify("");
  130. editInstance(rows[0]);
  131. }
  132. function getSelectedInstances() {
  133. return getSelectedTableRowIds("prefInstanceList");
  134. }