|
@@ -2,27 +2,47 @@
|
|
|
* Created by Mai on 2017/4/1.
|
|
|
*/
|
|
|
var PROJECT = {
|
|
|
- createNew: function () {
|
|
|
- // 定义private方法
|
|
|
- var tools = {};
|
|
|
+ createNew: function (projectID, userID) {
|
|
|
+ // 瀹氫箟private鏂规硶
|
|
|
+ var tools = {
|
|
|
+ _ID: projectID,
|
|
|
+ _userID: userID,
|
|
|
+ updateLock: 0,
|
|
|
+ updateData: [],
|
|
|
+ operation: '',
|
|
|
+ modules: {},
|
|
|
|
|
|
- // 所有通过this访问的属性,都不应在此单元外部进行写入操作
|
|
|
+ doAfterUpdate: function(result){
|
|
|
+ result.forEach(function(item){
|
|
|
+ if (item.moduleName in this.modules){
|
|
|
+ this.modules[item.moduleName].doAfterUpdate(item.err, item.data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 所有通过this访问的属性,都不应在此单元外部进行写入操作
|
|
|
var project = function () {
|
|
|
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'};
|
|
|
};
|
|
|
|
|
|
- // prototype用于定义public方法
|
|
|
+ // prototype鐢ㄤ簬瀹氫箟public鏂规硶
|
|
|
project.prototype.modify = function (modifyDatas, callback) {
|
|
|
// To Do
|
|
|
};
|
|
|
|
|
|
+ // prototype鐢ㄤ簬瀹氫箟public鏂规硶
|
|
|
+ project.prototype.ID = function () {
|
|
|
+ return tools._ID;
|
|
|
+ };
|
|
|
+
|
|
|
project.prototype.loadMainTree = function () {
|
|
|
var that = this;
|
|
|
var loadRationNode = function (rations, cacheNode) {
|
|
@@ -31,7 +51,7 @@ var PROJECT = {
|
|
|
if (ration[that.masterField.ration] && ration[that.masterField.ration] === cacheNode.source.getID()) {
|
|
|
newNode = that.mainTree.addNode(cacheNode);
|
|
|
newNode.source = ration;
|
|
|
- newNode.sourceType = that.Rations.getSourceType();
|
|
|
+ newNode.sourceType = that.Ration.getSourceType();
|
|
|
newNode.data = ration;
|
|
|
}
|
|
|
});
|
|
@@ -45,7 +65,7 @@ var PROJECT = {
|
|
|
newNode.data = nodes[i].data;
|
|
|
|
|
|
if (nodes[i].children.length === 0) {
|
|
|
- loadRationNode(that.Rations.datas, newNode);
|
|
|
+ loadRationNode(that.Ration.datas, newNode);
|
|
|
} else {
|
|
|
loadIdTreeNode(nodes[i].children, newNode);
|
|
|
}
|
|
@@ -53,7 +73,93 @@ var PROJECT = {
|
|
|
};
|
|
|
loadIdTreeNode(this.Bills.tree.roots, null);
|
|
|
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
|
|
|
+ }
|
|
|
+ tools.updateLock += 1;
|
|
|
+ };
|
|
|
+
|
|
|
+ project.prototype.endUpdate = function(){
|
|
|
+ if (tools.updateLock === 0){
|
|
|
+ throw "project can not endUpdate before beginUpdate";
|
|
|
+ }
|
|
|
+ tools.updateLock -= 1;
|
|
|
+ if (tools.updateLock === 0) {
|
|
|
+ $.ajax({
|
|
|
+ type: "POST",
|
|
|
+ url: '/project/save',
|
|
|
+ data: {'data': JSON.stringify({
|
|
|
+ "project_id": tools._ID,
|
|
|
+ "user_id": tools._userID,
|
|
|
+ "date": new Date,
|
|
|
+ "operation": tools.operation,
|
|
|
+ "update_data": tools.updateData
|
|
|
+ })},
|
|
|
+ dataType: 'json',
|
|
|
+ cache: false,
|
|
|
+ timeout: 50000,
|
|
|
+ success: function (result) {
|
|
|
+ if (result.error === 0) {
|
|
|
+ tools.doAfterUpdate(result.data);
|
|
|
+ } else {
|
|
|
+ alert('error: ' + result.message);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ error: function(jqXHR, textStatus, errorThrown){
|
|
|
+ alert('error ' + textStatus + " " + errorThrown);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ tools.updateData = [];
|
|
|
+ tools.operation = "";
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ project.prototype.push = function(moduleName, data){
|
|
|
+ if (tools.updateLock === 0){
|
|
|
+ throw "project can not push data before beginUpdate";
|
|
|
+ };
|
|
|
+ var moduleData = {
|
|
|
+ moduleName: moduleName,
|
|
|
+ data: data
|
|
|
+ };
|
|
|
+ tools.updateData.push(moduleData);
|
|
|
+ };
|
|
|
+
|
|
|
+ project.prototype.registerModule = function(moduleName, obj){
|
|
|
+ if (!tools.modules.hasOwnProperty(moduleName)){
|
|
|
+ tools.modules[moduleName] = obj;
|
|
|
+ }
|
|
|
+ };
|
|
|
|
|
|
return new project();
|
|
|
}
|