UNPKG

@progress/kendo-ui

Version:

This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.

295 lines (216 loc) 9.42 kB
module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) /******/ return installedModules[moduleId].exports; /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ exports: {}, /******/ id: moduleId, /******/ loaded: false /******/ }; /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ // Flag the module as loaded /******/ module.loaded = true; /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ // Load entry module and return exports /******/ return __webpack_require__(0); /******/ }) /************************************************************************/ /******/ ({ /***/ 0: /***/ (function(module, exports, __webpack_require__) { __webpack_require__(1535); module.exports = __webpack_require__(1535); /***/ }), /***/ 3: /***/ (function(module, exports) { module.exports = function() { throw new Error("define cannot be used indirect"); }; /***/ }), /***/ 5: /***/ (function(module, exports) { module.exports = require("../kendo.data"); /***/ }), /***/ 19: /***/ (function(module, exports) { module.exports = require("../kendo.core"); /***/ }), /***/ 1500: /***/ (function(module, exports) { module.exports = require("./sheet"); /***/ }), /***/ 1535: /***/ (function(module, exports, __webpack_require__) { var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;(function(f, define){ !(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(19), __webpack_require__(5), __webpack_require__(1500) ], __WEBPACK_AMD_DEFINE_FACTORY__ = (f), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); })(function(){ (function(kendo) { if (kendo.support.browser.msie && kendo.support.browser.version < 9) { return; } var identity = function(o) { return o; }; var SheetDataSourceBinder = kendo.Class.extend({ init: function(options) { this.options = kendo.jQuery.extend({}, this.options, options); this.columns = this._normalizeColumns(this.options.columns); this._sheet(); this._dataSource(); this._header(); this._boundRowsCount = 0; this.dataSource.fetch(); }, _sheet: function() { this.sheet = this.options.sheet; this._sheetChangeHandler = this._sheetChange.bind(this); this._sheetDeleteRowHandler = this._sheetDeleteRow.bind(this); this._sheetInsertRowHandler = this._sheetInsertRow.bind(this); this.sheet.bind("change", this._sheetChangeHandler) .bind("afterDeleteRow", this._sheetDeleteRowHandler) .bind("afterInsertRow", this._sheetInsertRowHandler); }, _sheetInsertRow: function(e) { if (e.index !== undefined) { this.dataSource.insert(Math.max(e.index - 1, 0), {}); } }, _sheetDeleteRow: function(e) { if (e.index !== undefined) { var dataSource = this.dataSource; var model = dataSource.view()[e.index - 1]; if (model) { dataSource.remove(model); } } }, _header: function() { this.sheet.batch(function() { this.columns.forEach(function(column, index) { this.sheet.range(0,index).value(column.title); }.bind(this)); }.bind(this)); }, _sheetChange: function(e) { if (e.insertRow || e.deleteRow) { // these actions are handled via custom events return; } if (e.recalc && e.ref) { var dataSource = this.dataSource; var data = dataSource.view(); var columns = this.columns; var fields; if (dataSource.reader.model) { fields = dataSource.reader.model.fields; } if (!columns.length && data.length) { columns = Object.keys(data[0].toJSON()); } var getters = columns.map(function(column) { var field = column.field; if (field && fields && fields[field] && fields[field].type == "date") { return kendo.spreadsheet.numberToDate; } return identity; }); this._skipRebind = true; var normalizedRef = this.sheet._grid.normalize(e.ref); var values = this.sheet.range(normalizedRef).values(); normalizedRef.forEach(function(ref) { ref = ref.toRangeRef(); var record; var valueIndex = 0; for (var ri = ref.topLeft.row; ri <= ref.bottomRight.row; ri++) { record = data[ri - 1]; // skip header row if (!record) { record = dataSource.insert(ri - 1, {}); data = dataSource.view(); } var colValueIndex = 0; for (var ci = ref.topLeft.col; ci <= ref.bottomRight.col && ci < columns.length; ci++) { record.set(columns[ci].field, getters[ci](values[valueIndex][colValueIndex++])); } valueIndex++; } }); this._boundRowsCount = dataSource.view().length; this._skipRebind = false; } }, _normalizeColumns: function(columns) { return columns.map(function(column) { var field = column.field || column; return { field: field, title: column.title || field }; }); }, _dataSource: function() { var options = this.options; var dataSource = options.dataSource; dataSource = Array.isArray(dataSource) ? { data: dataSource } : dataSource; if (this.dataSource && this._changeHandler) { this.dataSource.unbind("change", this._changeHandler); } else { this._changeHandler = this._change.bind(this); } this.dataSource = kendo.data.DataSource.create(dataSource) .bind("change", this._changeHandler); }, _change: function() { if (this._skipRebind) { return; } if (this.sheet.trigger("dataBinding")) { return; } var data = this.dataSource.view(); var columns = this.columns; if (!columns.length && data.length) { this.columns = columns = this._normalizeColumns(Object.keys(data[0].toJSON())); this._header(); } var getters = columns.map(function(column) { return kendo.getter(column.field); }); this.sheet.batch(function() { var length = Math.max(data.length, this._boundRowsCount); for (var idx = 0; idx < length; idx++) { for (var getterIdx = 0; getterIdx < getters.length; getterIdx++) { var value = data[idx] ? getters[getterIdx](data[idx]) : null; //skip header row this.sheet.range(idx + 1, getterIdx).value(value); } } }.bind(this)); this._boundRowsCount = data.length; this.sheet.trigger("dataBound"); }, destroy: function() { this.dataSource.unbind("change", this._changeHandler); this.sheet.unbind("change", this._sheetChangeHandler) .unbind("deleteRow", this._sheetDeleteRowHandler) .unbind("insertRow", this._sheetInsertRowHandler); }, options: { columns: [] } }); kendo.spreadsheet.SheetDataSourceBinder = SheetDataSourceBinder; })(kendo); }, __webpack_require__(3)); /***/ }) /******/ });