chadoNodeApi_updateVerticalTabSummary.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. (function ($) {
  2. Drupal.behaviors.chadoNodeApiFieldsetSummaries = {
  3. attach: function (context) {
  4. // Properties Tab
  5. $('fieldset.chado-node-api.properties', context).drupalSetSummary(function (context) {
  6. return ChadoNodeApi_getSummary({
  7. machineName: {
  8. plural: 'properties',
  9. singular:'property'
  10. },
  11. readableName: {
  12. plural: 'properties',
  13. singular:'property'
  14. }
  15. });
  16. });
  17. // External References Tab
  18. $('fieldset.chado-node-api.dbxrefs', context).drupalSetSummary(function (context) {
  19. return ChadoNodeApi_getSummary({
  20. machineName: {
  21. plural: 'dbxrefs',
  22. singular:'dbxref'
  23. },
  24. readableName: {
  25. plural: 'references',
  26. singular:'reference'
  27. }
  28. });
  29. });
  30. // Relationships Tab
  31. $('fieldset.chado-node-api.relationships', context).drupalSetSummary(function (context) {
  32. return ChadoNodeApi_getSummary({
  33. machineName: {
  34. plural: 'relationships',
  35. singular:'relationship'
  36. },
  37. readableName: {
  38. plural: 'relationships',
  39. singular:'relationship'
  40. }
  41. });
  42. });
  43. function ChadoNodeApi_getSummary(api) {
  44. var numCurrent = $('tr.' + api.machineName.singular).length;
  45. var numOriginal = $('input.num-' + api.machineName.plural, context).val();
  46. var numSaved = $('tr.saved.' + api.machineName.singular).length;
  47. var numUnsaved = $('tr.unsaved.' + api.machineName.singular).length;
  48. var numRemoved = numOriginal - numSaved;
  49. // If there are no rows then tell the user that.
  50. if (numCurrent == 0) {
  51. if (numRemoved == 0) {
  52. return Drupal.t('No ' + api.readableName.plural);
  53. }
  54. else {
  55. return Drupal.t('No ' + api.readableName.plural + ' (<span class="chado-node-api removed">' + numRemoved + ' removed</span>)');
  56. }
  57. }
  58. // Otherwise, give them a breakdown of the current, new and removed rows
  59. // NOTE: Removed rows include only those that were original and have since been removed.
  60. else {
  61. var apiReadable = api.readableName.plural;
  62. if (numCurrent == 1) {
  63. apiReadable = api.readableName.singular;
  64. }
  65. if (numUnsaved != 0 && numRemoved != 0) {
  66. return Drupal.t(numCurrent + ' ' + apiReadable + ' (<span class="chado-node-api new">' + numUnsaved + ' new</span>; <span class="chado-node-api removed">' + numRemoved + ' removed</span>)');
  67. }
  68. else if (numRemoved != 0) {
  69. return Drupal.t(numCurrent + ' ' + apiReadable + ' (<span class="chado-node-api removed">' + numRemoved + ' removed</span>)');
  70. }
  71. else if (numUnsaved != 0) {
  72. return Drupal.t(numCurrent + ' ' + apiReadable + ' (<span class="chado-node-api new">' + numUnsaved + ' new</span>)');
  73. }
  74. else {
  75. return Drupal.t(numCurrent + ' ' + apiReadable);
  76. }
  77. }
  78. }
  79. }};
  80. })(jQuery);