|
@@ -5,11 +5,20 @@ var PROJECT = {
|
|
|
createNew: function (projectID, userID) {
|
|
|
// 定义private方法
|
|
|
var tools = {
|
|
|
- _projectID: projectID,
|
|
|
+ _ID: projectID,
|
|
|
_userID: userID,
|
|
|
updateLock: 0,
|
|
|
updateData: [],
|
|
|
- operation: ''
|
|
|
+ operation: '',
|
|
|
+ modules: {},
|
|
|
+
|
|
|
+ doAfterUpdate: function(result){
|
|
|
+ result.forEach(function(item){
|
|
|
+ if (item.moduleName in this.modules){
|
|
|
+ this.modules[item.moduleName].doAfterUpdate(item.err, item.data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
// 所有通过this访问的属性,都不应在此单元外部进行写入操作
|
|
@@ -17,8 +26,8 @@ var PROJECT = {
|
|
|
this.mainTree = cacheTree.createNew(this);
|
|
|
|
|
|
this.Bills = Bills.createNew(this);
|
|
|
- this.Rations = Rations.createNew(this);
|
|
|
- this.GLJs = GLJs.createNew(this);
|
|
|
+ this.Ration = Ration.createNew(this);
|
|
|
+ this.GLJ = GLJ.createNew(this);
|
|
|
|
|
|
|
|
|
this.masterField = {ration: 'BillsID'};
|
|
@@ -29,6 +38,11 @@ var PROJECT = {
|
|
|
// To Do
|
|
|
};
|
|
|
|
|
|
+ // prototype用于定义public方法
|
|
|
+ project.prototype.ID = function () {
|
|
|
+ return tools._ID;
|
|
|
+ };
|
|
|
+
|
|
|
project.prototype.loadMainTree = function () {
|
|
|
var that = this;
|
|
|
var loadRationNode = function (rations, cacheNode) {
|
|
@@ -61,6 +75,33 @@ var PROJECT = {
|
|
|
this.mainTree.sortTreeItems();
|
|
|
};
|
|
|
|
|
|
+ // 提供给各模块调用的统一从后台获取数据的方法
|
|
|
+ project.prototype.pullData = function (url, data, successCallback, errorCallback) {
|
|
|
+ $.ajax({
|
|
|
+ type:"POST",
|
|
|
+ url: url,
|
|
|
+ data: {'data': JSON.stringify(data)},
|
|
|
+ dataType: 'json',
|
|
|
+ cache: false,
|
|
|
+ timeout: 50000,
|
|
|
+ success: function(result){
|
|
|
+ successCallback(result);
|
|
|
+ },
|
|
|
+ error: function(jqXHR, textStatus, errorThrown){
|
|
|
+ alert('error ' + textStatus + " " + errorThrown);
|
|
|
+ errorCallback();
|
|
|
+ }
|
|
|
+ });
|
|
|
+ };
|
|
|
+
|
|
|
+ // 所有模块在此从后台获取数据
|
|
|
+ project.prototype.loadDatas = function (){
|
|
|
+ this.Bills.pullData();
|
|
|
+ this.Ration.pullData();
|
|
|
+ this.GLJ.pullData();
|
|
|
+
|
|
|
+ };
|
|
|
+
|
|
|
project.prototype.beginUpdate = function(operation){
|
|
|
if (tools.updateLock === 0){
|
|
|
tools.operation = operation
|
|
@@ -78,7 +119,7 @@ var PROJECT = {
|
|
|
type: "POST",
|
|
|
url: '/project/save',
|
|
|
data: {'data': JSON.stringify({
|
|
|
- "project_id": tools._projectID,
|
|
|
+ "project_id": tools._ID,
|
|
|
"user_id": tools._userID,
|
|
|
"date": new Date,
|
|
|
"operation": tools.operation,
|
|
@@ -89,7 +130,7 @@ var PROJECT = {
|
|
|
timeout: 50000,
|
|
|
success: function (result) {
|
|
|
if (result.error === 0) {
|
|
|
- // to do callback(result.data);
|
|
|
+ tools.doAfterUpdate(result.data);
|
|
|
} else {
|
|
|
alert('error: ' + result.message);
|
|
|
}
|
|
@@ -104,6 +145,9 @@ var PROJECT = {
|
|
|
};
|
|
|
|
|
|
project.prototype.push = function(moduleName, data){
|
|
|
+ if (tools.updateLock === 0){
|
|
|
+ throw "project can not push data before beginUpdate";
|
|
|
+ };
|
|
|
var moduleData = {
|
|
|
moduleName: moduleName,
|
|
|
data: data
|
|
@@ -111,6 +155,12 @@ var PROJECT = {
|
|
|
tools.updateData.push(moduleData);
|
|
|
};
|
|
|
|
|
|
+ project.prototype.registerModule = function(moduleName, obj){
|
|
|
+ if (!tools.modules.hasOwnProperty(moduleName)){
|
|
|
+ tools.modules[moduleName] = obj;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
return new project();
|
|
|
}
|
|
|
};
|