/*
This file is part of Ice Framework.
Ice Framework is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Ice Framework is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Ice Framework. If not, see .
------------------------------------------------------------------
Original work Copyright (c) 2012 [Gamonoid Media Pvt. Ltd]
Developer: Thilina Hasantha (thilina.hasantha[at]gmail.com / facebook.com/thilinah)
*/
function AdapterBase(endPoint) {
}
this.moduleRelativeURL = null;
this.tableData = new Array();
this.sourceData = new Array();
this.filter = null;
this.origFilter = null;
this.orderBy = null;
this.currentElement = null;
AdapterBase.inherits(IceHRMBase);
AdapterBase.method('initAdapter' , function(endPoint,tab,filter,orderBy) {
this.moduleRelativeURL = baseUrl;
this.table = endPoint;
if(tab == undefined || tab == null){
this.tab = endPoint;
}else{
this.tab = tab;
}
if(filter == undefined || filter == null){
this.filter = null;
}else{
this.filter = filter;
}
this.origFilter = this.filter;
if(orderBy == undefined || orderBy == null){
this.orderBy = null;
}else{
this.orderBy = orderBy;
}
this.trackEvent("initAdapter",tab);
this.requestCache = new RequestCache();
});
AdapterBase.method('setFilter', function(filter) {
this.filter = filter;
});
AdapterBase.method('getFilter', function() {
return this.filter;
});
AdapterBase.method('setOrderBy', function(orderBy) {
this.orderBy = orderBy;
});
AdapterBase.method('getOrderBy', function() {
return this.orderBy;
});
/**
* @method add
* @param object {Array} object data to be added to database
* @param getFunctionCallBackData {Array} once a success is returned call get() function for this module with these parameters
* @param callGetFunction {Boolean} if false the get function of the module will not be called (default: true)
* @param successCallback {Function} this will get called after success response
*/
AdapterBase.method('add', function(object,getFunctionCallBackData,callGetFunction,successCallback) {
var that = this;
if(callGetFunction == undefined || callGetFunction == null){
callGetFunction = true;
}
$(object).attr('a','add');
$(object).attr('t',this.table);
that.showLoader();
$.post(this.moduleRelativeURL, object, function(data) {
if(data.status == "SUCCESS"){
that.addSuccessCallBack(getFunctionCallBackData,data.object, callGetFunction, successCallback, that);
}else{
that.addFailCallBack(getFunctionCallBackData,data.object);
}
},"json").always(function() {that.hideLoader()});
this.trackEvent("add",this.tab,this.table);
});
AdapterBase.method('addSuccessCallBack', function(callBackData,serverData, callGetFunction, successCallback, thisObject) {
if(callGetFunction){
this.get(callBackData);
}
this.initFieldMasterData();
if(successCallback != undefined && successCallback != null){
successCallback.apply(thisObject,[serverData]);
}
this.trackEvent("addSuccess",this.tab,this.table);
});
AdapterBase.method('addFailCallBack', function(callBackData,serverData) {
try{
this.closePlainMessage();
}catch(e){}
this.showMessage("Error saving",serverData);
this.trackEvent("addFailed",this.tab,this.table);
});
AdapterBase.method('deleteObj', function(id,callBackData) {
var that = this;
that.showLoader();
$.post(this.moduleRelativeURL, {'t':this.table,'a':'delete','id':id}, function(data) {
if(data.status == "SUCCESS"){
that.deleteSuccessCallBack(callBackData,data.object);
}else{
that.deleteFailCallBack(callBackData,data.object);
}
},"json").always(function() {that.hideLoader()});
this.trackEvent("delete",this.tab,this.table);
});
AdapterBase.method('deleteSuccessCallBack', function(callBackData,serverData) {
this.get(callBackData);
this.clearDeleteParams();
});
AdapterBase.method('deleteFailCallBack', function(callBackData,serverData) {
this.clearDeleteParams();
this.showMessage("Error Occurred while Deleting Item",serverData);
});
AdapterBase.method('get', function(callBackData) {
var that = this;
if(this.getRemoteTable()){
this.createTableServer(this.getTableName());
$("#"+this.getTableName()+'Form').hide();
$("#"+this.getTableName()).show();
return;
}
var sourceMappingJson = JSON.stringify(this.getSourceMapping());
var filterJson = "";
if(this.getFilter() != null){
filterJson = JSON.stringify(this.getFilter());
}
var orderBy = "";
if(this.getOrderBy() != null){
orderBy = this.getOrderBy();
}
sourceMappingJson = this.fixJSON(sourceMappingJson);
filterJson = this.fixJSON(filterJson);
that.showLoader();
$.post(this.moduleRelativeURL, {'t':this.table,'a':'get','sm':sourceMappingJson,'ft':filterJson,'ob':orderBy}, function(data) {
if(data.status == "SUCCESS"){
that.getSuccessCallBack(callBackData,data.object);
}else{
that.getFailCallBack(callBackData,data.object);
}
},"json").always(function() {that.hideLoader()});
that.initFieldMasterData();
this.trackEvent("get",this.tab,this.table);
//var url = this.getDataUrl();
//console.log(url);
});
AdapterBase.method('getDataUrl', function(columns) {
var that = this;
var sourceMappingJson = JSON.stringify(this.getSourceMapping());
var columns = JSON.stringify(columns);
var filterJson = "";
if(this.getFilter() != null){
filterJson = JSON.stringify(this.getFilter());
}
var orderBy = "";
if(this.getOrderBy() != null){
orderBy = this.getOrderBy();
}
var url = this.moduleRelativeURL.replace("service.php","data.php");
url = url+"?"+"t="+this.table;
url = url+"&"+"sm="+this.fixJSON(sourceMappingJson);
url = url+"&"+"cl="+this.fixJSON(columns);
url = url+"&"+"ft="+this.fixJSON(filterJson);
url = url+"&"+"ob="+orderBy;
if(this.isSubProfileTable()){
url = url+"&"+"type=sub";
}
if(this.remoteTableSkipProfileRestriction()){
url = url+"&"+"skip=1";
}
return url;
});
AdapterBase.method('isSubProfileTable', function() {
return false;
});
AdapterBase.method('remoteTableSkipProfileRestriction', function() {
return false;
});
AdapterBase.method('preProcessTableData', function(row) {
return row;
});
AdapterBase.method('getSuccessCallBack', function(callBackData,serverData) {
var data = [];
var mapping = this.getDataMapping();
for(var i=0;i';
var editButton = '';
var table = $('');
//add Header
var header = this.getSubHeader();
table.append(header);
if(data.length == 0){
table.append(''+this.getNoDataMessage()+'');
}else{
for(var i=0;i