UNPKG

7.42 kBJavaScriptView Raw
1(function(a,b){"object"==typeof exports&&"undefined"!=typeof module?b(exports):"function"==typeof define&&define.amd?define(["exports"],b):(a=a||self,b(a.dataObjectConnect={}))})(this,function(a){"use strict";function b(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function c(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function d(a,b,d){return b&&c(a.prototype,b),d&&c(a,d),a}function e(){return e=Object.assign||function(a){for(var b,c=1;c<arguments.length;c++)for(var d in b=arguments[c],b)Object.prototype.hasOwnProperty.call(b,d)&&(a[d]=b[d]);return a},e.apply(this,arguments)}function f(a,b){if("function"!=typeof b&&null!==b)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(b&&b.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),b&&h(a,b)}function g(a){return g=Object.setPrototypeOf?Object.getPrototypeOf:function(a){return a.__proto__||Object.getPrototypeOf(a)},g(a)}function h(a,b){return h=Object.setPrototypeOf||function(a,b){return a.__proto__=b,a},h(a,b)}function i(a){if(void 0===a)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return a}function j(a,b){return b&&("object"==typeof b||"function"==typeof b)?b:i(a)}const{React:k}=window,l=k.PureComponent,m=k.Component,n=k.useState,o=k.useEffect;var p=["AllowDeleteChanged","AllowUpdateChanged","AllowInsertChanged","SaveFailed","PartialDataLoaded","DataLoadFailed","FieldChanged","RecordCreated","RecordRefreshed","RecordDeleting","RecordDeleted","AfterSave","BeforeLoad","BeforeSave","CancelEdit","CurrentIndexChanged","DataLoaded","DirtyChanged"];a.dataObjectConnect=function(a){var c=!!(1<arguments.length&&arguments[1]!==void 0)&&arguments[1];return function(h){function l(){return"string"==typeof a?window[a]:a}var m=function(a){function m(a){var d;b(this,m),d=j(this,g(m).call(this,a));var e={},f=l();if(c){var h=!0,k=!1,n=void 0;try{for(var o,p,q=f.getFields()[Symbol.iterator]();!(h=(o=q.next()).done);h=!0)p=o.value,e[p.name]=null}catch(a){k=!0,n=a}finally{try{h||null==q.return||q.return()}finally{if(k)throw n}}}else e.data=[];return d.state=Object.assign({canDelete:f.isDeleteAllowed(),canUpdate:f.isUpdateAllowed(),canInsert:f.isInsertAllowed(),currentIndex:f.getCurrentIndex(),isDirty:f.isDirty(),isDeleting:!1,isLoading:!0===f.isDataLoading(),isSaving:!1,loadError:null,saveFailed:!1},e),d.handleAfterSave=d.handleAfterSave.bind(i(i(d))),d.handleAllowDeleteChanged=d.handleAllowDeleteChanged.bind(i(i(d))),d.handleAllowInsertChanged=d.handleAllowInsertChanged.bind(i(i(d))),d.handleAllowUpdateChanged=d.handleAllowUpdateChanged.bind(i(i(d))),d.handleBeforeLoad=d.handleBeforeLoad.bind(i(i(d))),d.handleBeforeSave=d.handleBeforeSave.bind(i(i(d))),d.handleCancelEdit=d.handleCancelEdit.bind(i(i(d))),d.handleCurrentIndexChanged=d.handleCurrentIndexChanged.bind(i(i(d))),d.handleDataLoaded=d.handleDataLoaded.bind(i(i(d))),d.handleDataLoadFailed=d.handleDataLoadFailed.bind(i(i(d))),d.handleDirtyChanged=d.handleDirtyChanged.bind(i(i(d))),d.handlePartialDataLoaded=d.handlePartialDataLoaded.bind(i(i(d))),d.handleRecordDeleting=d.handleRecordDeleting.bind(i(i(d))),d.handleRecordDeleted=d.handleRecordDeleted.bind(i(i(d))),d.handleSaveFailed=d.handleSaveFailed.bind(i(i(d))),d.setFieldValue=d.setFieldValue.bind(i(i(d))),d.setFieldValues=d.setFieldValues.bind(i(i(d))),d.updateData=d.updateData.bind(i(i(d))),d.handleFieldChanged=d.updateData,d.handleRecordCreated=d.updateData,d.handleRecordRefreshed=d.updateData,d}return f(m,a),d(m,[{key:"componentDidMount",value:function(){for(var a,b=l(),c=0;c<p.length;c++)a=p[c],b.attachEvent("on"+a,this["handle"+a]);this.updateData()}},{key:"componentWillUnmount",value:function(){for(var a,b=l(),c=0;c<p.length;c++)a=p[c],b.detachEvent("on"+a,this["handle"+a])}},{key:"cancelEdit",value:function(){l().cancelEdit()}},{key:"deleteRow",value:function(a){var b=l();return new Promise(function(d){var e=function(a,b){d({data:b,error:a})};c?b.deleteCurrentRow(e):b.deleteRow(a,e)})}},{key:"endEdit",value:function(a){var b=l();return new Promise(function(c){b.endEdit(function(b,d){"function"==typeof a&&a(b,d),c({data:d,error:b})})})}},{key:"updateData",value:function(){var a=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},b=l();if(c){var d=b.currentRow();this.setState(Object.assign(d,a))}else{var e=b.getData(),f=b.currentRow();this.setState(Object.assign({current:f,data:e},a))}}},{key:"handleAllowDeleteChanged",value:function(a){this.setState({canDelete:a})}},{key:"handleAllowUpdateChanged",value:function(a){this.setState({canUpdate:a})}},{key:"handleAllowInsertChanged",value:function(a){this.setState({canInsert:a})}},{key:"handleSaveFailed",value:function(){this.setState({saveFailed:!0})}},{key:"handlePartialDataLoaded",value:function(){return null}},{key:"handleDataLoadFailed",value:function(a){a?this.setState({isLoading:!1,loadError:a}):this.setState({isLoading:!1})}},{key:"handleRecordDeleting",value:function(){this.setState({isDeleting:!0})}},{key:"handleRecordDeleted",value:function(){this.updateData({isDeleting:!1})}},{key:"handleAfterSave",value:function(){this.updateData({isSaving:!1})}},{key:"handleBeforeLoad",value:function(){this.setState({isLoading:!0})}},{key:"handleBeforeSave",value:function(){this.setState({isSaving:!0,saveFailed:!1})}},{key:"handleCancelEdit",value:function(){this.updateData({isSaving:!1})}},{key:"handleCurrentIndexChanged",value:function(a){c?this.updateData():(this.updateData(),this.setState({currentIndex:a}))}},{key:"handleDataLoaded",value:function(){this.updateData({isLoading:!1,isSaving:!1,isDeleting:!1,saveFailed:!1})}},{key:"handleDirtyChanged",value:function(){this.setState({isDirty:l().isDirty()})}},{key:"refreshData",value:function(a){var b=l();return new Promise(function(c){b.refreshDataSource(function(b,d){"function"==typeof a&&a(b,d),c({data:d,error:b})})})}},{key:"refreshRow",value:function(a){var b=l();return new Promise(function(c){b.refreshCurrentRow(function(b,d){"function"==typeof a&&a(b,d),c({data:d,error:b})})})}},{key:"setFieldValue",value:function(a,b){l().currentRow(a,b),this.updateData()}},{key:"setFieldValues",value:function(a){var b=l();for(var c in a)a.hasOwnProperty(c)&&b.currentRow(c,a[c]);this.updateData()}},{key:"setCurrentIndex",value:function(a){l().setCurrentIndex(a)}},{key:"setParameter",value:function(){var a;(a=l()).setParameter.apply(a,arguments)}},{key:"render",value:function(){return k.createElement(h,e({},this.state,{onCancelEdit:this.cancelEdit,onCurrentIndexChange:this.setCurrentIndex,onDeleteRow:this.deleteRow,onEndEdit:this.endEdit,onFieldChange:this.setFieldValue,onFieldsChange:this.setFieldValues,onRefreshData:this.refreshData,onRefreshRow:this.refreshRow,onSetParameter:this.setParameter},this.props))}}]),m}(k.Component);return m.displayName="string"==typeof a?a:a.getDataSourceId(),m.displayName+="(".concat(function(){return h.displayName||h.name||"Component"}(),")"),m}},a.properties=["onCancelEdit","onCurrentIndexChange","onEndEdit","onDeleteRow","onFieldChange","onFieldsChange","onRefreshData","onRefreshRow","onSetParameter","canDelete","canUpdate","canInsert","currentIndex","isDirty","isDeleting","isLoading","isSaving","loadError","saveFailed"],Object.defineProperty(a,"__esModule",{value:!0})});