chadoNodeApi_unsavedNotify.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. (function ($) {
  2. Drupal.behaviors.chadoNodeApiChangeNotify = {
  3. attach: function (context) {
  4. ChadoNodeApi_notifyChanges({
  5. machineName: {
  6. plural: 'properties',
  7. singular:'property'
  8. },
  9. readableName: {
  10. plural: 'properties',
  11. singular:'property'
  12. }
  13. });
  14. ChadoNodeApi_notifyChanges({
  15. machineName: {
  16. plural: 'dbxrefs',
  17. singular:'dbxref'
  18. },
  19. readableName: {
  20. plural: 'references',
  21. singular:'reference'
  22. }
  23. });
  24. ChadoNodeApi_notifyChanges({
  25. machineName: {
  26. plural: 'relationships',
  27. singular:'relationship'
  28. },
  29. readableName: {
  30. plural: 'relationships',
  31. singular:'relationship'
  32. }
  33. });
  34. function ChadoNodeApi_notifyChanges(api) {
  35. var numCurrent = $('tr.' + api.machineName.singular).length;
  36. var numOriginal = $('input.num-' + api.machineName.plural, context).val();
  37. var numSaved = $('tr.saved.' + api.machineName.singular).length;
  38. var numUnsaved = $('tr.unsaved.' + api.machineName.singular).length;
  39. var numRemoved = numOriginal - numSaved;
  40. // If changes have been made then notify the user.
  41. if (numUnsaved > 0 || numRemoved > 0) {
  42. // Make the warning visible.
  43. $('#' + api.machineName.singular + '-save-warning').css("display","inherit");
  44. // Determine singular versus plural.
  45. var unsavedReadable = api.readableName.plural;
  46. if (numUnsaved == 1) {
  47. unsavedReadable = api.readableName.singular;
  48. }
  49. var removedReadable = api.readableName.plural;
  50. if (numRemoved == 1) {
  51. removedReadable = api.readableName.singular;
  52. }
  53. // Specify the changes made in the warning.
  54. var note = '';
  55. if (numUnsaved > 0 && numRemoved > 0) {
  56. note = 'NOTE: Changes include the addition of ' + numUnsaved + ' ' + unsavedReadable + ' and the removal of ' + numRemoved + ' saved ' + removedReadable + '.';
  57. }
  58. else if (numUnsaved > 0) {
  59. note = 'NOTE: Changes include the addition of ' + numUnsaved + ' ' + unsavedReadable + '.';
  60. }
  61. else if (numRemoved > 0) {
  62. note = 'NOTE: Changes include the removal of ' + numRemoved + ' saved ' + removedReadable + '.';
  63. }
  64. $('#' + api.machineName.singular + '-save-warning span.specific-changes').html(note);
  65. // Add a * to any new records to make the warning more accessible.
  66. $('tr.unsaved.' + api.machineName.singular + ' span.row-unsaved-warning').html('*');
  67. }
  68. }
  69. }};
  70. })(jQuery);