Subversion Repositories Applications.papyrus

Rev

Rev 1318 | Details | Compare with Previous | Last modification | View Log | RSS feed

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