Base.js
上传用户:kimgenplus
上传日期:2016-06-05
资源大小:20877k
文件大小:4k
源码类别:

OA系统

开发平台:

Java

  1. /*
  2. Copyright (c) 2004-2006, The Dojo Foundation
  3. All Rights Reserved.
  4. Licensed under the Academic Free License version 2.1 or above OR the
  5. modified BSD license. For more information on Dojo licensing, see:
  6. http://dojotoolkit.org/community/licensing.shtml
  7. */
  8. dojo.provide("dojo.data.old.provider.Base");
  9. dojo.require("dojo.lang.assert");
  10. dojo.data.old.provider.Base = function () {
  11. this._countOfNestedTransactions = 0;
  12. this._changesInCurrentTransaction = null;
  13. };
  14. dojo.data.old.provider.Base.prototype.beginTransaction = function () {
  15. if (this._countOfNestedTransactions === 0) {
  16. this._changesInCurrentTransaction = [];
  17. }
  18. this._countOfNestedTransactions += 1;
  19. };
  20. dojo.data.old.provider.Base.prototype.endTransaction = function () {
  21. this._countOfNestedTransactions -= 1;
  22. dojo.lang.assert(this._countOfNestedTransactions >= 0);
  23. if (this._countOfNestedTransactions === 0) {
  24. var listOfChangesMade = this._saveChanges();
  25. this._changesInCurrentTransaction = null;
  26. if (listOfChangesMade.length > 0) {
  27. this._notifyObserversOfChanges(listOfChangesMade);
  28. }
  29. }
  30. };
  31. dojo.data.old.provider.Base.prototype.getNewItemToLoad = function () {
  32. return this._newItem();
  33. };
  34. dojo.data.old.provider.Base.prototype.newItem = function (itemName) {
  35. dojo.lang.assertType(itemName, String, {optional:true});
  36. var item = this._newItem();
  37. if (itemName) {
  38. item.set("name", itemName);
  39. }
  40. return item;
  41. };
  42. dojo.data.old.provider.Base.prototype.newAttribute = function (attributeId) {
  43. dojo.lang.assertType(attributeId, String, {optional:true});
  44. var attribute = this._newAttribute(attributeId);
  45. return attribute;
  46. };
  47. dojo.data.old.provider.Base.prototype.getAttribute = function (attributeId) {
  48. dojo.unimplemented("dojo.data.old.provider.Base");
  49. var attribute;
  50. return attribute;
  51. };
  52. dojo.data.old.provider.Base.prototype.getAttributes = function () {
  53. dojo.unimplemented("dojo.data.old.provider.Base");
  54. return this._arrayOfAttributes;
  55. };
  56. dojo.data.old.provider.Base.prototype.fetchArray = function () {
  57. dojo.unimplemented("dojo.data.old.provider.Base");
  58. return [];
  59. };
  60. dojo.data.old.provider.Base.prototype.fetchResultSet = function () {
  61. dojo.unimplemented("dojo.data.old.provider.Base");
  62. var resultSet;
  63. return resultSet;
  64. };
  65. dojo.data.old.provider.Base.prototype.noteChange = function (item, attribute, value) {
  66. var change = {item:item, attribute:attribute, value:value};
  67. if (this._countOfNestedTransactions === 0) {
  68. this.beginTransaction();
  69. this._changesInCurrentTransaction.push(change);
  70. this.endTransaction();
  71. } else {
  72. this._changesInCurrentTransaction.push(change);
  73. }
  74. };
  75. dojo.data.old.provider.Base.prototype.addItemObserver = function (item, observer) {
  76. dojo.lang.assertType(item, dojo.data.old.Item);
  77. item.addObserver(observer);
  78. };
  79. dojo.data.old.provider.Base.prototype.removeItemObserver = function (item, observer) {
  80. dojo.lang.assertType(item, dojo.data.old.Item);
  81. item.removeObserver(observer);
  82. };
  83. dojo.data.old.provider.Base.prototype._newItem = function () {
  84. var item = new dojo.data.old.Item(this);
  85. return item;
  86. };
  87. dojo.data.old.provider.Base.prototype._newAttribute = function (attributeId) {
  88. var attribute = new dojo.data.old.Attribute(this);
  89. return attribute;
  90. };
  91. dojo.data.old.provider.Base.prototype._saveChanges = function () {
  92. var arrayOfChangesMade = this._changesInCurrentTransaction;
  93. return arrayOfChangesMade;
  94. };
  95. dojo.data.old.provider.Base.prototype._notifyObserversOfChanges = function (arrayOfChanges) {
  96. var arrayOfResultSets = this._getResultSets();
  97. for (var i in arrayOfChanges) {
  98. var change = arrayOfChanges[i];
  99. var changedItem = change.item;
  100. var arrayOfItemObservers = changedItem.getObservers();
  101. for (var j in arrayOfItemObservers) {
  102. var observer = arrayOfItemObservers[j];
  103. observer.observedObjectHasChanged(changedItem, change);
  104. }
  105. for (var k in arrayOfResultSets) {
  106. var resultSet = arrayOfResultSets[k];
  107. var arrayOfResultSetObservers = resultSet.getObservers();
  108. for (var m in arrayOfResultSetObservers) {
  109. observer = arrayOfResultSetObservers[m];
  110. observer.observedObjectHasChanged(resultSet, change);
  111. }
  112. }
  113. }
  114. };
  115. dojo.data.old.provider.Base.prototype._getResultSets = function () {
  116. dojo.unimplemented("dojo.data.old.provider.Base");
  117. return [];
  118. };