/*!@license
* Infragistics.Web.ClientUI igDataSource KnockoutJS extension 14.1.20141.1020
*
* Copyright (c) 2011-2014 Infragistics Inc.
*
* http://www.infragistics.com/
*
* Depends on:
*	jquery-1.7.1.js
*	ig.util.js
*	ig.dataSource.js
*/
(function($){$.ig.KnockoutDataSource=$.ig.KnockoutDataSource||$.ig.DataSource.extend({init:function(options){if(options.observableDataSource===null||options.observableDataSource===undefined){this.kods=options.dataSource;options.dataSource=ko.toJS(options.dataSource)}else{this.kods=options.observableDataSource;options.dataSource=ko.toJS(options.observableDataSource)}this._super(options);return this},setCellValue:function(rowId,colId,val,autoCommit){this._super(rowId,colId,val,autoCommit)},_setCellValue:function(rowId,colId,val){var cellData,pk=this.settings.primaryKey,ds=this.kods,i;ds=ko.isObservable(ds)?ds():ds;if(this.settings.responseDataKey){if(ko.isObservable(ds[this.settings.responseDataKey])){ds=ds[this.settings.responseDataKey]()}else if(ds[this.settings.responseDataKey]){ds=ds[this.settings.responseDataKey]}}if(pk){for(i=0;i<ds.length;i++){cellData=ko.isObservable(ds[i][pk])?ds[i][pk]():ds[i][pk];if(String(cellData)===String(rowId)){if(ko.isObservable(ds[i][colId])){ds[i][colId](val)}else{ds[i][colId]=val}break}}}else{ds[rowId][colId](val)}},deleteRow:function(rowId,autoCommit){if(autoCommit){this._ownUpdate=!this._ownUpdate}this._super(rowId,autoCommit)},_deleteRow:function(rowId){var pk=this.settings.primaryKey,ds=this.kods;if(this.settings.responseDataKey&&ds[this.settings.responseDataKey]){ds=ds[this.settings.responseDataKey]}if(ko.isObservable(ds)){if(!this._koUpdate){ds.remove(function(item){return String(ko.isObservable(item[pk])?item[pk]():item[pk])===String(rowId)})}else{this._koUpdate=false}}else{this._super(rowId)}},addRow:function(rowId,rowObject,autoCommit){if(autoCommit){this._ownUpdate=!this._ownUpdate}this._super(rowId,rowObject,autoCommit)},_addRow:function(rowObject,rowId){var ds=this.kods,prop,koObject=jQuery.extend({},rowObject);if(this.settings.responseDataKey&&ds[this.settings.responseDataKey]){ds=ds[this.settings.responseDataKey]}if(ko.isObservable(ds)){if(!this._koUpdate){for(prop in koObject){if(koObject.hasOwnProperty(prop)&&!ko.isObservable(prop)){koObject[prop]=ko.observable(koObject[prop])}}this._super(rowObject,rowId);ds.push(koObject)}else{this._koUpdate=false;this._super(rowObject,rowId)}}else{ds.push(rowObject);this._super(rowObject,rowId)}},updateRow:function(rowId,rowObject,autoCommit){if(autoCommit){this._ownUpdate=!this._ownUpdate}this._super(rowId,rowObject,autoCommit)},_updateRow:function(rowId,rowObject){var cellData,pk=this.settings.primaryKey,ds=this.kods,prop,i;if(this.settings.responseDataKey&&ds[this.settings.responseDataKey]){ds=ds[this.settings.responseDataKey]}ds=ko.isObservable(ds)?ds():ds;if(pk){for(i=0;i<ds.length;i++){cellData=ko.isObservable(ds[i][pk])?ds[i][pk]():ds[i][pk];if(String(cellData)===String(rowId)){for(prop in rowObject){if(rowObject.hasOwnProperty(prop)){if(ko.isObservable(ds[i][prop])){ds[i][prop](rowObject[prop])}else{ds[i][prop]=rowObject[prop]}}}break}}}else{for(prop in rowObject){if(rowObject.hasOwnProperty(prop)){if(ko.isObservable(ds[rowId][prop])){ds[rowId][prop](rowObject[prop])}else{ds[rowId][prop]=rowObject[prop]}}}}},_commitTransaction:function(t){var i,prop,rec;this._ownUpdate=true;if(this.settings.primaryKey===null){rec=this._data[parseInt(t.rowId,10)]}else{rec=this.findRecordByKey(t.rowId)}if(t.type==="cell"){rec[t.col]=t.value;this._setCellValue(t.rowId,t.col,t.value)}else if(t.type==="row"){if($.type(t.row)==="array"){for(i=0;i<t.row.length;i++){rec[i]=t.row[i]}}else if(rec){for(prop in t.row){if(t.row.hasOwnProperty(prop)){rec[prop]=t.row[prop]}}this._updateRow(t.rowId,t.row)}}else if(t.type==="deleterow"){if(this.settings.primaryKey===null){this.removeRecordByIndex(parseInt(t.rowId,10))}else{this.removeRecordByKey(t.rowId)}this._deleteRow(t.rowId)}else if(t.type==="newrow"){this._addRow(t.row,t.rowId)}else if(t.type==="insertrow"){this._addRow(t.row,t.rowIndex)}this._removeTransactionByTransactionId(t.tid)},dataAt:function(path,keyspath){var data=this.kods,paths=path.split("/"),kp=keyspath.split("/"),k,i,tmp,j,cd=null,ckey=this.settings.primaryKey,ckeyval="",ckeys=[],ckeyvals=[],match=false;data=ko.isObservable(data)?data():data;for(i=0;i<paths.length;i++){ckey=paths[i].split(":")[0];ckeyval=paths[i].split(":")[1];if(paths[i]!==""){for(j=0;data&&j<data.length;j++){if(ckey&&ckey.indexOf(",")!==-1){ckeys=ckey.split(",");ckeyvals=ckeyval.split(",");for(k=0;k<ckeys.length;k++){tmp=data[j][ckeys[k]];tmp=ko.isObservable(tmp)?tmp():tmp;if(!tmp.charAt&&ckeyvals[k].charAt){ckeyvals[k]=parseInt(ckeyvals[k],10)}match=tmp===ckeyvals[k];if(!match){break}}}else{tmp=data[j][ckey];tmp=ko.isObservable(tmp)?tmp():tmp;if(tmp!==undefined&&!tmp.charAt&&ckeyval.charAt){ckeyval=parseInt(ckeyval,10)}match=tmp===ckeyval}if(match){cd=data[j][kp[i]];if(paths.length>1&&i<paths.length-1&&this.settings.responseDataKey&&$.type(cd)!=="array"&&cd[this.settings.responseDataKey]){if(ko.isObservable(cd[this.settings.responseDataKey])){cd=cd[this.settings.responseDataKey]()}else{cd=cd[this.settings.responseDataKey]}}break}}data=ko.isObservable(cd)?cd():cd}}return cd}})})(jQuery);(function($){$(document).ready(function(){var wm=$("#__ig_wm__").length>0?$("#__ig_wm__"):$('<div id="__ig_wm__"></div>').appendTo(document.body);wm.css({position:"fixed",bottom:0,right:0,zIndex:1e3}).addClass("ui-igtrialwatermark")})})(jQuery);