services.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Licensed to Jasig under one or more contributor license
  3. * agreements. See the NOTICE file distributed with this work
  4. * for additional information regarding copyright ownership.
  5. * Jasig licenses this file to you under the Apache License,
  6. * Version 2.0 (the "License"); you may not use this file
  7. * except in compliance with the License. You may obtain a
  8. * copy of the License at the following location:
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing,
  13. * software distributed under the License is distributed on an
  14. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  15. * KIND, either express or implied. See the License for the
  16. * specific language governing permissions and limitations
  17. * under the License.
  18. */
  19. function updateRegisteredServiceOrder(movedService, pos) {
  20. var COLUMN_SERVICE_ID = "td1";
  21. var COLUMN_SERVICE_EVAL_ORDER = "td8";
  22. var rowId = $(movedService).attr('id');
  23. var serviceId = $('#' + rowId + ' td.' + COLUMN_SERVICE_ID).attr('id');
  24. var evalOrder = $('#' + rowId + ' td.ac.' + COLUMN_SERVICE_EVAL_ORDER).html();
  25. var targetRow = $(pos).attr('element');
  26. var relPosition = $(pos).attr('position');
  27. var targetRowId = $(targetRow).attr('id');
  28. var targetRowEvalOrder = $('#' + targetRowId + ' td.ac.' + COLUMN_SERVICE_EVAL_ORDER).html();
  29. switch (relPosition) {
  30. case fluid.position.BEFORE:
  31. evalOrder = eval(targetRowEvalOrder) - 1;
  32. break;
  33. case fluid.position.AFTER:
  34. evalOrder = eval(targetRowEvalOrder) + 1;
  35. break;
  36. }
  37. var result = false;
  38. $.ajax({
  39. type: "POST",
  40. async: false,
  41. url: "updateRegisteredServiceEvaluationOrder.html",
  42. data: { id: serviceId, evaluationOrder: evalOrder },
  43. success:
  44. function(data, textStatus, jqXHR) {
  45. $('#' + rowId + ' td.ac.' + COLUMN_SERVICE_EVAL_ORDER).html(evalOrder);
  46. result = true;
  47. },
  48. error:
  49. function(jqXHR, textStatus, errorThrown) {
  50. $("#errorsDiv").show();
  51. console.log(data.error);
  52. }
  53. });
  54. return result;
  55. }
  56. $(document).ready(function () {
  57. $("#errorsDiv").hide();
  58. var opts = {
  59. selectors: {
  60. movables: "tr"
  61. },
  62. listeners: {
  63. onMove: updateRegisteredServiceOrder,
  64. onBeginMove: function() {
  65. $("#errorsDiv").hide();
  66. },
  67. afterMove: function() {
  68. $("#fluid-ariaLabeller-liveRegion").remove();
  69. },
  70. onHover: function(item, state) {
  71. $(item).css('cursor', state ? 'move' : 'auto');
  72. }
  73. }
  74. };
  75. return fluid.reorderList("#tableWrapper #scrollTable tbody", opts);
  76. });