Subversion Repositories Applications.papyrus

Rev

Go to most recent revision | Details | 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
 
11
dojo.provide("dojo.data.old.provider.Base");
12
dojo.require("dojo.lang.assert");
13
dojo.data.old.provider.Base = function () {
14
	this._countOfNestedTransactions = 0;
15
	this._changesInCurrentTransaction = null;
16
};
17
dojo.data.old.provider.Base.prototype.beginTransaction = function () {
18
	if (this._countOfNestedTransactions === 0) {
19
		this._changesInCurrentTransaction = [];
20
	}
21
	this._countOfNestedTransactions += 1;
22
};
23
dojo.data.old.provider.Base.prototype.endTransaction = function () {
24
	this._countOfNestedTransactions -= 1;
25
	dojo.lang.assert(this._countOfNestedTransactions >= 0);
26
	if (this._countOfNestedTransactions === 0) {
27
		var listOfChangesMade = this._saveChanges();
28
		this._changesInCurrentTransaction = null;
29
		if (listOfChangesMade.length > 0) {
30
			this._notifyObserversOfChanges(listOfChangesMade);
31
		}
32
	}
33
};
34
dojo.data.old.provider.Base.prototype.getNewItemToLoad = function () {
35
	return this._newItem();
36
};
37
dojo.data.old.provider.Base.prototype.newItem = function (itemName) {
38
	dojo.lang.assertType(itemName, String, {optional:true});
39
	var item = this._newItem();
40
	if (itemName) {
41
		item.set("name", itemName);
42
	}
43
	return item;
44
};
45
dojo.data.old.provider.Base.prototype.newAttribute = function (attributeId) {
46
	dojo.lang.assertType(attributeId, String, {optional:true});
47
	var attribute = this._newAttribute(attributeId);
48
	return attribute;
49
};
50
dojo.data.old.provider.Base.prototype.getAttribute = function (attributeId) {
51
	dojo.unimplemented("dojo.data.old.provider.Base");
52
	var attribute;
53
	return attribute;
54
};
55
dojo.data.old.provider.Base.prototype.getAttributes = function () {
56
	dojo.unimplemented("dojo.data.old.provider.Base");
57
	return this._arrayOfAttributes;
58
};
59
dojo.data.old.provider.Base.prototype.fetchArray = function () {
60
	dojo.unimplemented("dojo.data.old.provider.Base");
61
	return [];
62
};
63
dojo.data.old.provider.Base.prototype.fetchResultSet = function () {
64
	dojo.unimplemented("dojo.data.old.provider.Base");
65
	var resultSet;
66
	return resultSet;
67
};
68
dojo.data.old.provider.Base.prototype.noteChange = function (item, attribute, value) {
69
	var change = {item:item, attribute:attribute, value:value};
70
	if (this._countOfNestedTransactions === 0) {
71
		this.beginTransaction();
72
		this._changesInCurrentTransaction.push(change);
73
		this.endTransaction();
74
	} else {
75
		this._changesInCurrentTransaction.push(change);
76
	}
77
};
78
dojo.data.old.provider.Base.prototype.addItemObserver = function (item, observer) {
79
	dojo.lang.assertType(item, dojo.data.old.Item);
80
	item.addObserver(observer);
81
};
82
dojo.data.old.provider.Base.prototype.removeItemObserver = function (item, observer) {
83
	dojo.lang.assertType(item, dojo.data.old.Item);
84
	item.removeObserver(observer);
85
};
86
dojo.data.old.provider.Base.prototype._newItem = function () {
87
	var item = new dojo.data.old.Item(this);
88
	return item;
89
};
90
dojo.data.old.provider.Base.prototype._newAttribute = function (attributeId) {
91
	var attribute = new dojo.data.old.Attribute(this);
92
	return attribute;
93
};
94
dojo.data.old.provider.Base.prototype._saveChanges = function () {
95
	var arrayOfChangesMade = this._changesInCurrentTransaction;
96
	return arrayOfChangesMade;
97
};
98
dojo.data.old.provider.Base.prototype._notifyObserversOfChanges = function (arrayOfChanges) {
99
	var arrayOfResultSets = this._getResultSets();
100
	for (var i in arrayOfChanges) {
101
		var change = arrayOfChanges[i];
102
		var changedItem = change.item;
103
		var arrayOfItemObservers = changedItem.getObservers();
104
		for (var j in arrayOfItemObservers) {
105
			var observer = arrayOfItemObservers[j];
106
			observer.observedObjectHasChanged(changedItem, change);
107
		}
108
		for (var k in arrayOfResultSets) {
109
			var resultSet = arrayOfResultSets[k];
110
			var arrayOfResultSetObservers = resultSet.getObservers();
111
			for (var m in arrayOfResultSetObservers) {
112
				observer = arrayOfResultSetObservers[m];
113
				observer.observedObjectHasChanged(resultSet, change);
114
			}
115
		}
116
	}
117
};
118
dojo.data.old.provider.Base.prototype._getResultSets = function () {
119
	dojo.unimplemented("dojo.data.old.provider.Base");
120
	return [];
121
};
122