gc.spread.sheets.angularjs.11.2.2.js 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360
  1. /*
  2. *
  3. * Spread.Sheets Library
  4. *
  5. * Copyright(c) GrapeCity, Inc. All rights reserved.
  6. *
  7. * Licensed under the SpreadJS Commercial License.
  8. * us.sales@grapecity.com
  9. * http://www.grapecity.com/en/licensing/grapecity/
  10. *
  11. *
  12. **/
  13. var angular = angular, GC = GC, $ = $; // for eslint
  14. (function () {
  15. 'use strict';
  16. var m = angular.module('gcspreadsheets', []);
  17. function ColumnWrapper() {
  18. this.headerText = '';
  19. this.dataField = '';
  20. }
  21. ColumnWrapper.prototype = {
  22. width: function (value) {
  23. if (arguments.length === 0) {
  24. if (this.column) {
  25. return this.column.width();
  26. }
  27. return undefined;
  28. }
  29. this._width = value;
  30. if (this.column) {
  31. this.column.width(value);
  32. }
  33. return this;
  34. },
  35. visible: function (value) {
  36. if (arguments.length === 0) {
  37. if (this.column) {
  38. return this.column.visible();
  39. }
  40. return undefined;
  41. }
  42. this._visible = value;
  43. if (this.column) {
  44. this.column.visible(value);
  45. }
  46. return this;
  47. }, resizable: function (value) {
  48. if (arguments.length === 0) {
  49. if (this.column) {
  50. return this.column.resizable();
  51. }
  52. return undefined;
  53. }
  54. this._resizable = value;
  55. if (this.column) {
  56. this.column.resizable(value);
  57. }
  58. return this;
  59. },
  60. defaultStyle: function (value) {
  61. if (arguments.length === 0) {
  62. if (this.sheet) {
  63. return this.sheet.getStyle(-1, this.index, GC.Spread.Sheets.SheetArea.viewport);
  64. }
  65. return null;
  66. }
  67. this._defaultStyle = value;
  68. if (this.sheet) {
  69. this.sheet.setStyle(-1, this.index, value, GC.Spread.Sheets.SheetArea.viewport);
  70. }
  71. return this;
  72. },
  73. dataValidation: function(value) {
  74. if (arguments.length === 0) {
  75. if (this.sheet) {
  76. return this.sheet.getDataValidator(-1, this.index, GC.Spread.Sheets.SheetArea.viewport);
  77. }
  78. return null;
  79. }
  80. var validator = value.validator;
  81. this._validator = validator;
  82. if (this.sheet) {
  83. this.sheet.setDataValidator(-1, this.index, validator, GC.Spread.Sheets.SheetArea.viewport);
  84. }
  85. return this;
  86. },
  87. attach: function (sheet, column, index) {
  88. this.sheet = sheet;
  89. this.column = column;
  90. this.index = index;
  91. this.updata();
  92. },
  93. updata: function () {
  94. this.sheet.suspendEvent();
  95. if (this._width !== undefined) {
  96. this.column.width(this._width);
  97. }
  98. if (this._visible !== undefined) {
  99. this.column.visible(this._visible);
  100. }
  101. if (this._resizable !== undefined) {
  102. this.column.resizable(this._resizable);
  103. }
  104. if (this._defaultStyle) {
  105. this.sheet.setStyle(-1, this.index, this._defaultStyle, GC.Spread.Sheets.SheetArea.viewport);
  106. }
  107. if (this._validator) {
  108. this.sheet.setDataValidator(-1, this.index, this._validator, GC.Spread.Sheets.SheetArea.viewport);
  109. }
  110. if (this.autoFit) {
  111. this.sheet.autoFitColumn(this.index);
  112. }
  113. this.sheet.resumeEvent();
  114. }
  115. }
  116. GC.Spread.Sheets.ColumnWrapper = ColumnWrapper;
  117. // Simple wraaper for save DataValidator
  118. GC.Spread.Sheets.DataValidatorWrapper = function() {
  119. this.validator = null;
  120. };
  121. function lineBorderConverter(stringValue) {
  122. if (!stringValue) {
  123. return undefined;
  124. }
  125. stringValue = stringValue.trim();
  126. var parts;
  127. if (stringValue.indexOf(',') >= 0) {
  128. parts = stringValue.split(',');
  129. } else {
  130. parts = stringValue.split(' ');
  131. }
  132. var lineBorder = new GC.Spread.Sheets.LineBorder();
  133. lineBorder.color = parts[0].trim();
  134. if (parts.length > 1) {
  135. lineBorder.style = GC.Spread.Sheets.LineStyle[parts[1].trim()];
  136. }
  137. return lineBorder;
  138. }
  139. function setValidator(wrapper, validatorType, value) {
  140. if (!wrapper || !validatorType) {
  141. return;
  142. }
  143. validatorType = validatorType.toLowerCase();
  144. var validator;
  145. if (validatorType === 'numbervalidator') {
  146. validator = GC.Spread.Sheets.DataValidation.createNumberValidator(value.comparisonOperator, value.value1, value.value2, value.isIntegervalue);
  147. } else if (validatorType === 'datevalidator') {
  148. validator = GC.Spread.Sheets.DataValidation.createDateValidator(value.comparisonOperator, value.value1, value.value2);
  149. } else if (validatorType === 'textlengthvalidator') {
  150. validator = GC.Spread.Sheets.DataValidation.createTextLengthValidator(value.comparisonOperator, value.value1, value.value2);
  151. } else if (validatorType === 'formulavalidator') {
  152. validator = GC.Spread.Sheets.DataValidation.createFormulaValidator(value.formula);
  153. } else if (validatorType === 'formulalistvalidator') {
  154. validator = GC.Spread.Sheets.DataValidation.createFormulaListValidator(value.formulaList);
  155. } else if (validatorType === 'listvalidator') {
  156. validator = GC.Spread.Sheets.DataValidation.createListValidator(value.list);
  157. }
  158. if (validator) {
  159. if (value.ignoreBlank !== undefined) {
  160. validator.ignoreBlank(value.ignoreBlank);
  161. }
  162. if (value.inCellDropdown !== undefined) {
  163. validator.inCellDropdown(value.inCellDropdown);
  164. }
  165. if (value.showInputMessage !== undefined) {
  166. validator.showInputMessage(value.showInputMessage);
  167. }
  168. if (value.showErrorMessage !== undefined) {
  169. validator.showErrorMessage(value.showErrorMessage);
  170. }
  171. if (value.errorStyle !== undefined) {
  172. validator.errorStyle(value.errorStyle);
  173. }
  174. if (value.inputMessage !== undefined) {
  175. validator.inputMessage(value.inputMessage);
  176. }
  177. if (value.inputTitle !== undefined) {
  178. validator.inputTitle(value.inputTitle);
  179. }
  180. if (value.errorMessage !== undefined) {
  181. validator.errorMessage(value.errorMessage);
  182. }
  183. if (value.errorTitle !== undefined) {
  184. validator.errorTitle(value.errorTitle);
  185. }
  186. wrapper.validator = validator;
  187. }
  188. }
  189. function setDataValidationResult(spread, name, value) {
  190. spread._angularDataValidationResult = value;
  191. }
  192. function setComboboxItems(comboBoxCellType, itemType, value) {
  193. if (value.text === undefined && value.value === undefined) {
  194. return;
  195. }
  196. if (value.text === undefined) {
  197. value.text = value.value;
  198. } else if (value.value === undefined) {
  199. value.value = value.text;
  200. }
  201. var items;
  202. if (!comboBoxCellType.items()) {
  203. items = [];
  204. comboBoxCellType.items(items);
  205. } else {
  206. items = comboBoxCellType.items();
  207. }
  208. items.push(value);
  209. }
  210. function setSheetOutline(sheet, outlineType, value) {
  211. if (outlineType && value.outlines) {
  212. outlineType = outlineType.toLowerCase().trim();
  213. angular.forEach(value.outlines, function (outlineInfo) {
  214. if (outlineType === 'rowoutlines') {
  215. sheet.rowOutlines.group(outlineInfo.index, outlineInfo.count);
  216. } else {
  217. sheet.columnOutlines.group(outlineInfo.index, outlineInfo.count);
  218. }
  219. });
  220. }
  221. }
  222. function addOutLine(outlineGroup, outLineType, value) {
  223. if (!outlineGroup.outlines) {
  224. outlineGroup.outlines = [];
  225. }
  226. outlineGroup.outlines.push(value);
  227. }
  228. function getCurrentTheme(sheet, property) {
  229. return sheet[property]().name();
  230. }
  231. function setColumns(sheet, name, value) {
  232. sheet._columnDefs = value;
  233. }
  234. function setSheets(spread, name, value) {
  235. spread._sheetDefs = value;
  236. value.spread = spread;
  237. }
  238. function addColumn(columns, name, value) {
  239. columns.push(value);
  240. }
  241. function addSheet(sheets, name, value) {
  242. sheets.push(value);
  243. sheets.spread.addSheet(sheets.length - 1, value);
  244. }
  245. function setDataSource(sheet, name, value) {
  246. sheet._angularDataSource = value;
  247. }
  248. function setBorder(border, name, value) {
  249. if (!border.borderLeft) {
  250. border.borderLeft = value;
  251. }
  252. if (!border.borderTop) {
  253. border.borderTop = value;
  254. }
  255. if (!border.borderRight) {
  256. border.borderRight = value;
  257. }
  258. if (!border.borderBottom) {
  259. border.borderBottom = value;
  260. }
  261. }
  262. function getOptionValue(sheet, option) {
  263. return sheet.options[option];
  264. }
  265. function setOptionValue(sheet, option, value) {
  266. sheet.options[option] = value;
  267. }
  268. var styleDef = {
  269. 'backcolor': {'type': 'string', 'name': 'backColor'},
  270. 'forecolor': {'type': 'string', 'name': 'foreColor'},
  271. 'halign': {'type': 'enum, HorizontalAlign', 'name': 'hAlign'},
  272. 'valign': {'type': 'enum, VerticalAlign', 'name': 'vAlign'},
  273. 'font': {'type': 'string', 'name': 'font'},
  274. 'themefont': {'type': 'string', 'name': 'themeFont'},
  275. 'formatter': {'type': 'string', 'name': 'formatter'},
  276. 'border': {
  277. 'type': 'LineBordeer',
  278. 'name': 'border',
  279. 'getProperties': ['borderLeft', 'borderTop', 'borderRight', 'borderBottom'],
  280. 'setFunction': setBorder,
  281. 'converter': lineBorderConverter
  282. },
  283. 'borderleft': {'type': 'LineBorder', 'name': 'borderLeft', 'converter': lineBorderConverter},
  284. 'bordertop': {'type': 'LineBorder', 'name': 'borderTop', 'converter': lineBorderConverter},
  285. 'borderright': {'type': 'LineBorder', 'name': 'borderRight', 'converter': lineBorderConverter},
  286. 'borderbottom': {'type': 'LineBorder', 'name': 'borderBottom', 'converter': lineBorderConverter},
  287. 'locked': {'type': 'boolean', 'name': 'locked'},
  288. 'wordwrap': {'type': 'boolean', 'name': 'wordWrap'},
  289. 'textindent': {'type': 'number', 'name': 'textIndent'},
  290. 'shrinktofit': {'type': 'boolean', 'name': 'shrinkToFit'},
  291. 'backgroundimage': {'type': 'string', 'name': 'backgroundImage'},
  292. 'backgroundimagelayout': {'type': 'enum, ImageLayout', 'name': 'backgroundImageLayout'},
  293. 'textcelltype': {
  294. 'type': 'GC.Spread.Sheets.CellTypes.Text', 'name': 'cellType', 'properties': {}
  295. },
  296. 'buttoncelltype': {
  297. 'type': 'GC.Spread.Sheets.CellTypes.Button', 'name': 'cellType', 'properties': {
  298. 'buttonbackcolor': {'type': 'string', 'name': 'buttonBackColor', 'setFunction': 'buttonBackColor'},
  299. 'marginleft': {'type': 'number', 'name': 'marginLeft', 'setFunction': 'marginLeft'},
  300. 'margintop': {'type': 'number', 'name': 'marginTop', 'setFunction': 'marginTop'},
  301. 'marginright': {'type': 'number', 'name': 'marginRight', 'setFunction': 'marginRight'},
  302. 'marginbottom': {'type': 'number', 'name': 'marginBottom', 'setFunction': 'marginBottom'},
  303. 'text': {'type': 'string', 'name': 'text', 'setFunction': 'text'}
  304. }
  305. },
  306. 'checkboxcelltype': {
  307. 'type': 'GC.Spread.Sheets.CellTypes.CheckBox', 'name': 'cellType', 'properties': {
  308. 'caption': {'type': 'string', 'name': 'caption', 'setFunction': 'caption'},
  309. 'isthreestate': {'type': 'boolean', 'name': 'isThreeState', 'setFunction': 'isThreeState'},
  310. 'textalign': {
  311. 'type': 'enum,GC.Spread.Sheets.CellTypes.CheckBoxTextAlign',
  312. 'name': 'textAlign',
  313. 'setFunction': 'textAlign'
  314. },
  315. 'textfalse': {'type': 'string', 'name': 'textFalse', 'setFunction': 'textFalse'},
  316. 'textindeterminate': {
  317. 'type': 'string',
  318. 'name': 'textIndeterminate',
  319. 'setFunction': 'textIndeterminate'
  320. },
  321. 'texttrue': {'type': 'string', 'name': 'textTrue', 'setFunction': 'textTrue'}
  322. }
  323. },
  324. 'comboboxcelltype': {
  325. 'type': 'GC.Spread.Sheets.CellTypes.ComboBox', 'name': 'cellType', 'properties': {
  326. 'editorvaluetype': {
  327. 'type': 'enum,GC.Spread.Sheets.CellTypes.EditorValueType',
  328. 'name': 'editorValueType',
  329. 'setFunction': 'editorValueType'
  330. },
  331. //'items': { 'type': '[string]', 'name': 'items', 'setFunction': 'items' },
  332. 'item': {
  333. 'type': 'object', 'name': 'items', 'setFunction': setComboboxItems, 'properties': {
  334. 'value': {'type': 'string', 'name': 'value'},
  335. 'text': {'type': 'string', 'name': 'text'}
  336. }
  337. }
  338. }
  339. },
  340. 'hyperlinkcelltype': {
  341. 'type': 'GC.Spread.Sheets.CellTypes.HyperLink', 'name': 'cellType', 'properties': {
  342. 'linkcolor': {'type': 'string', 'name': 'linkColor', 'setFunction': 'linkColor'},
  343. 'linktooltip': {'type': 'string', 'name': 'linkToolTip', 'setFunction': 'linkToolTip'},
  344. 'text': {'type': 'string', 'name': 'text', 'setFunction': 'text'},
  345. 'visitedlinkcolor': {'type': 'string', 'name': 'visitedLinkColor', 'setFunction': 'visitedLinkColor'}
  346. }
  347. }
  348. }
  349. var validationsDef = {
  350. 'numbervalidator': {
  351. 'type': 'object', 'name': 'numberValidator', 'setFunction': setValidator, 'properties': {
  352. 'comparisonoperator': {
  353. 'type': 'enum,GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators',
  354. 'name': 'comparisonOperator'
  355. },
  356. 'value1': { 'type': 'string', 'name': 'value1' },
  357. 'value2': { 'type': 'string', 'name': 'value2' },
  358. 'isintegervalue': { 'type': 'boolean', 'name': 'isIntegerValue' }
  359. }
  360. },
  361. 'datevalidator': {
  362. 'type': 'object', 'name': 'dateValidator', 'setFunction': setValidator, 'properties': {
  363. 'comparisonoperator': {
  364. 'type': 'enum,GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators',
  365. 'name': 'comparisonOperator'
  366. },
  367. 'value1': { 'type': 'string', 'name': 'value1' },
  368. 'value2': { 'type': 'string', 'name': 'value2' }
  369. }
  370. },
  371. 'textlengthvalidator': {
  372. 'type': 'object', 'name': 'textLengthValidator', 'setFunction': setValidator, 'properties': {
  373. 'comparisonoperator': {
  374. 'type': 'enum,GC.Spread.Sheets.ConditionalFormatting.ComparisonOperators',
  375. 'name': 'comparisonOperator'
  376. },
  377. 'value1': { 'type': 'string', 'name': 'value1' },
  378. 'value2': { 'type': 'string', 'name': 'value2' }
  379. }
  380. },
  381. 'formulavalidator': {
  382. 'type': 'object', 'name': 'formulaValidator', 'setFunction': setValidator, 'properties': {
  383. 'formula': { 'type': 'string', 'name': 'formula' }
  384. }
  385. },
  386. 'formulalistvalidator': {
  387. 'type': 'object', 'name': 'formulaListValidator', 'setFunction': setValidator, 'properties': {
  388. 'formulalist': { 'type': 'string', 'name': 'formulaList' }
  389. }
  390. },
  391. 'listvalidator': {
  392. 'type': 'object', 'name': 'listValidator', 'setFunction': setValidator, 'properties': {
  393. 'list': { 'type': 'string', 'name': 'list' }
  394. }
  395. }
  396. };
  397. var validators = ['numbervalidator', 'datevalidator', 'textlengthvalidator', 'formulavalidator', 'formulalistvalidator', 'listvalidator'];
  398. for (var i = 0; i < validators.length; i++) {
  399. var validatorProperties = validationsDef[validators[i]]['properties'];
  400. validatorProperties['ignoreblank'] = {'type': 'boolean', 'name': 'ignoreBlank'};
  401. validatorProperties['incelldropdown'] = {'type': 'boolean', 'name': 'inCellDropdown'};
  402. validatorProperties['showinputmessage'] = {'type': 'boolean', 'name': 'showInputMessage'};
  403. validatorProperties['showerrormessage'] = {'type': 'boolean', 'name': 'showErrorMessage'};
  404. validatorProperties['errorstyle'] = {
  405. 'type': 'enum, GC.Spread.Sheets.DataValidation.ErrorStyle',
  406. 'name': 'errorStyle'
  407. };
  408. validatorProperties['inputmessage'] = {'type': 'string', 'name': 'inputMessage'};
  409. validatorProperties['inputtitle'] = {'type': 'string', 'name': 'inputTitle'};
  410. validatorProperties['errormessage'] = {'type': 'string', 'name': 'errorMessage'};
  411. validatorProperties['errortitle'] = {'type': 'string', 'name': 'errorTitle'};
  412. }
  413. var outlineDef = {
  414. 'outline': {
  415. 'type': 'object', 'name': 'outline', 'setFunction': addOutLine, 'properties': {
  416. 'index': {'type': 'number', 'name': 'index'},
  417. 'count': {'type': 'number', 'name': 'count'}
  418. }
  419. }
  420. }
  421. var columnPropertyMap = {
  422. 'datafield': {'type': 'string', 'name': 'dataField'},
  423. 'headertext': {'type': 'string', 'name': 'headerText'},
  424. 'width': {'type': 'number', 'name': 'width', 'setFunction': 'width', 'getFunction': 'width'},
  425. 'visible': {'type': 'boolean', 'name': 'visible', 'setFunction': 'visible', 'getFunction': 'visible'},
  426. 'resizable': {'type': 'boolean', 'name': 'resizable', 'setFunction': 'resizable', 'getFunction': 'resizable'},
  427. 'defaultstyle': {
  428. 'type': 'Style',
  429. 'name': 'defaultStyle',
  430. 'setFunction': 'defaultStyle',
  431. 'getFunction': 'defaultStyle',
  432. 'properties': styleDef
  433. },
  434. 'datavalidation': {
  435. 'type': 'DataValidatorWrapper',
  436. 'name': 'dataValidation',
  437. 'setFunction': 'dataValidation',
  438. 'getFunction': 'dataValidation',
  439. 'properties': validationsDef
  440. },
  441. 'autofit': {'type': 'boolean', 'name': 'autoFit'}
  442. }
  443. var columnsDef = {
  444. 'column': {
  445. 'type': 'ColumnWrapper', 'name': 'column', 'setFunction': addColumn, 'properties': columnPropertyMap
  446. }
  447. }
  448. var sheetPropertyMap = {
  449. 'name': {'type': 'string', 'name': 'name', 'setFunction': 'name', 'getFunction': 'name'},
  450. 'frozentrailingcolumncount': {
  451. 'type': 'number',
  452. 'name': 'frozenTrailingColumnCount',
  453. 'setFunction': 'frozenTrailingColumnCount',
  454. 'getFunction': 'frozenTrailingColumnCount'
  455. },
  456. 'frozentrailingrowcount': {
  457. 'type': 'number',
  458. 'name': 'frozenTrailingRowCount',
  459. 'setFunction': 'frozenTrailingRowCount',
  460. 'getFunction': 'frozenTrailingRowCount'
  461. },
  462. 'frozencolumncount': {
  463. 'type': 'number',
  464. 'name': 'frozenColumnCount',
  465. 'setFunction': 'frozenColumnCount',
  466. 'getFunction': 'frozenColumnCount'
  467. },
  468. 'frozenrowcount': {
  469. 'type': 'number',
  470. 'name': 'frozenRowCount',
  471. 'setFunction': 'frozenRowCount',
  472. 'getFunction': 'frozenRowCount'
  473. },
  474. 'defaultstyle': {
  475. 'type': 'Style',
  476. 'name': 'defaultStyle',
  477. 'setFunction': {
  478. 'name': 'setDefaultStyle',
  479. 'args': ['$value-replace$', GC.Spread.Sheets.SheetArea.viewport]
  480. },
  481. 'properties': styleDef
  482. },
  483. 'rowheaderdefaultstyle': {
  484. 'type': 'Style',
  485. 'name': 'rowHeaderDefaultStyle',
  486. 'setFunction': {
  487. 'name': 'setDefaultStyle',
  488. 'args': ['$value-replace$', GC.Spread.Sheets.SheetArea.rowHeader]
  489. },
  490. 'properties': styleDef
  491. },
  492. 'columnheaderdefaultstyle': {
  493. 'type': 'Style',
  494. 'name': 'columnHeaderDefaultStyle',
  495. 'setFunction': {
  496. 'name': 'setDefaultStyle',
  497. 'args': ['$value-replace$', GC.Spread.Sheets.SheetArea.colHeader]
  498. },
  499. 'properties': styleDef
  500. },
  501. 'allowcelloverflow': {
  502. 'type': 'boolean',
  503. 'name': 'allowCellOverflow',
  504. 'setFunction': setOptionValue,
  505. 'getFunction': getOptionValue
  506. },
  507. 'frozenlinecolor': {
  508. 'type': 'string',
  509. 'name': 'frozenlineColor',
  510. 'setFunction': setOptionValue,
  511. 'getFunction': getOptionValue
  512. },
  513. 'sheettabcolor': {
  514. 'type': 'string',
  515. 'name': 'sheetTabColor',
  516. 'setFunction': setOptionValue,
  517. 'getFunction': getOptionValue
  518. },
  519. 'rowcount': {'type': 'number', 'name': 'rowCount', 'setFunction': 'setRowCount', 'getFunction': 'getRowCount'},
  520. 'selectionpolicy': {
  521. 'type': 'enum, SelectionPolicy',
  522. 'name': 'selectionPolicy',
  523. 'setFunction': 'selectionPolicy',
  524. 'getFunction': 'selectionPolicy'
  525. },
  526. 'selectionunit': {
  527. 'type': 'enum,SelectionUnit',
  528. 'name': 'selectionUnit',
  529. 'setFunction': 'selectionUnit',
  530. 'getFunction': 'selectionUnit'
  531. },
  532. 'zoom': {'type': 'number', 'name': 'zoom', 'setFunction': 'zoom', 'getFunction': 'zoom'},
  533. 'currenttheme': {
  534. 'type': 'string',
  535. 'name': 'currentTheme',
  536. 'setFunction': 'currentTheme',
  537. 'getFunction': getCurrentTheme
  538. },
  539. 'clipboardoptions': {
  540. 'type': 'enum,ClipboardPasteOptions',
  541. 'name': 'clipBoardOptions',
  542. 'setFunction': setOptionValue,
  543. 'getFunction': getOptionValue
  544. },
  545. 'rowheadervisible': {
  546. 'type': 'boolean',
  547. 'name': 'rowHeaderVisible',
  548. 'setFunction': setOptionValue,
  549. 'getFunction': getOptionValue
  550. },
  551. 'colheadervisible': {
  552. 'type': 'boolean',
  553. 'name': 'colHeaderVisible',
  554. 'setFunction': setOptionValue,
  555. 'getFunction': getOptionValue
  556. },
  557. 'rowheaderautotext': {
  558. 'type': 'enum, HeaderAutoText',
  559. 'name': 'rowHeaderAutoText',
  560. 'setFunction': setOptionValue,
  561. 'getFunction': getOptionValue
  562. },
  563. 'colheaderautotext': {
  564. 'type': 'enum, HeaderAutoText',
  565. 'name': 'colHeaderAutoText',
  566. 'setFunction': setOptionValue,
  567. 'getFunction': getOptionValue
  568. },
  569. 'rowheaderautotextindex': {
  570. 'type': 'number',
  571. 'name': 'rowHeaderAutoTextIndex',
  572. 'setFunction': setOptionValue,
  573. 'getFunction': getOptionValue
  574. },
  575. 'colheaderautotextindex': {
  576. 'type': 'number',
  577. 'name': 'colHeaderAutoTextIndex',
  578. 'setFunction': setOptionValue,
  579. 'getFunction': getOptionValue
  580. },
  581. 'isprotected': {
  582. 'type': 'boolean',
  583. 'name': 'isProtected',
  584. 'setFunction': setOptionValue,
  585. 'getFunction': getOptionValue
  586. },
  587. 'showrowoutline': {
  588. 'type': 'boolean',
  589. 'name': 'showRowOutline',
  590. 'setFunction': 'showRowOutline',
  591. 'getFunction': 'showRowOutline'
  592. },
  593. 'showcolumnoutline': {
  594. 'type': 'boolean',
  595. 'name': 'showColumnOutline',
  596. 'setFunction': 'showColumnOutline',
  597. 'getFunction': 'showColumnOutline'
  598. },
  599. 'rowoutlines': {
  600. 'type': 'object',
  601. 'name': 'rowOutlines',
  602. 'setFunction': setSheetOutline,
  603. 'properties': outlineDef
  604. },
  605. 'columnoutlines': {
  606. 'type': 'object',
  607. 'name': 'columnOutlines',
  608. 'setFunction': setSheetOutline,
  609. 'properties': outlineDef
  610. },
  611. 'selectionbackcolor': {
  612. 'type': 'string',
  613. 'name': 'selectionBackColor',
  614. 'setFunction': setOptionValue,
  615. 'getFunction': getOptionValue
  616. },
  617. 'selectionbordercolor': {
  618. 'type': 'string',
  619. 'name': 'selectionBorderColor',
  620. 'setFunction': setOptionValue,
  621. 'getFunction': getOptionValue
  622. },
  623. 'columns': {'type': '[]', 'name': 'columns', 'setFunction': setColumns, 'properties': columnsDef},
  624. 'datasource': {'type': '[]', 'name': 'dataSource', 'setFunction': setDataSource},
  625. 'datasourcedeepwatch': {'type': 'boolean', 'name': 'dataSourceDeepWatch'}
  626. }
  627. var worksheetsDef = {
  628. 'worksheet': {
  629. 'type': 'Worksheet', 'name': 'worksheet', 'setFunction': addSheet, 'properties': sheetPropertyMap
  630. }
  631. }
  632. var workbookPropertyMap = {
  633. 'name': {'type': 'string', 'name': 'name'},
  634. 'allowuserzoom': {
  635. 'type': 'boolean',
  636. 'name': 'allowUserZoom',
  637. 'setFunction': setOptionValue,
  638. 'getFunction': getOptionValue
  639. },
  640. 'allowuserresize': {
  641. 'type': 'boolean',
  642. 'name': 'allowUserResize',
  643. 'setFunction': setOptionValue,
  644. 'getFunction': getOptionValue
  645. },
  646. 'tabstripvisible': {
  647. 'type': 'boolean',
  648. 'name': 'tabStripVisible',
  649. 'setFunction': setOptionValue,
  650. 'getFunction': getOptionValue
  651. },
  652. 'tabeditable': {
  653. 'type': 'boolean',
  654. 'name': 'tabEditable',
  655. 'setFunction': setOptionValue,
  656. 'getFunction': getOptionValue
  657. },
  658. 'newtabvisible': {
  659. 'type': 'boolean',
  660. 'name': 'newTabVisible',
  661. 'setFunction': setOptionValue,
  662. 'getFunction': getOptionValue
  663. },
  664. 'allowusereditformula': {
  665. 'type': 'boolean',
  666. 'name': 'allowUserEditFormula',
  667. 'setFunction': setOptionValue,
  668. 'getFunction': getOptionValue
  669. },
  670. 'autofittype': {
  671. 'type': 'enum, AutoFitType',
  672. 'name': 'autoFitType',
  673. 'setFunction': setOptionValue,
  674. 'getFunction': getOptionValue
  675. },
  676. 'allowuserdragfill': {
  677. 'type': 'boolean',
  678. 'name': 'allowUserDragFill',
  679. 'setFunction': setOptionValue,
  680. 'getFunction': getOptionValue
  681. },
  682. 'allowuserdragdrop': {
  683. 'type': 'boolean',
  684. 'name': 'allowUserDragDrop',
  685. 'setFunction': setOptionValue,
  686. 'getFunction': getOptionValue
  687. },
  688. 'highlightinvaliddata': {
  689. 'type': 'boolean',
  690. 'name': 'highlightInvalidData',
  691. 'setFunction': setOptionValue,
  692. 'getFunction': getOptionValue
  693. },
  694. 'referencestyle': {
  695. 'type': 'enum, ReferenceStyle',
  696. 'name': 'referenceStyle',
  697. 'setFunction': setOptionValue,
  698. 'getFunction': getOptionValue
  699. },
  700. 'backcolor': {
  701. 'type': 'string',
  702. 'name': 'backColor',
  703. 'setFunction': setOptionValue,
  704. 'getFunction': getOptionValue
  705. },
  706. 'grayareabackcolor': {
  707. 'type': 'string',
  708. 'name': 'grayAreaBackColor',
  709. 'setFunction': setOptionValue,
  710. 'getFunction': getOptionValue
  711. },
  712. 'backgroundimage': {
  713. 'type': 'string',
  714. 'name': 'backgroundImage',
  715. 'setFunction': setOptionValue,
  716. 'getFunction': getOptionValue
  717. },
  718. 'backgroundimagelayout': {
  719. 'type': 'enum, ImageLayout',
  720. 'name': 'backgroundImageLayout',
  721. 'setFunction': setOptionValue,
  722. 'getFunction': getOptionValue
  723. },
  724. 'showverticalscrollbar': {
  725. 'type': 'boolean',
  726. 'name': 'showVerticalScrollbar',
  727. 'setFunction': setOptionValue,
  728. 'getFunction': getOptionValue
  729. },
  730. 'showhorizontalscrollbar': {
  731. 'type': 'boolean',
  732. 'name': 'showHorizontalScrollbar',
  733. 'setFunction': setOptionValue,
  734. 'getFunction': getOptionValue
  735. },
  736. 'showscrolltip': {
  737. 'type': 'enum, ShowScrollTip',
  738. 'name': 'showScrollTip',
  739. 'setFunction': setOptionValue,
  740. 'getFunction': getOptionValue
  741. },
  742. 'showresizetip': {
  743. 'type': 'enum, ShowResizeTip',
  744. 'name': 'showResizeTip',
  745. 'setFunction': setOptionValue,
  746. 'getFunction': getOptionValue
  747. },
  748. 'showdragdroptip': {
  749. 'type': 'boolean',
  750. 'name': 'showDragDropTip',
  751. 'setFunction': setOptionValue,
  752. 'getFunction': getOptionValue
  753. },
  754. 'showdragfilltip': {
  755. 'type': 'boolean',
  756. 'name': 'showDragFillTip',
  757. 'setFunction': setOptionValue,
  758. 'getFunction': getOptionValue
  759. },
  760. 'datavalidationresult': {
  761. 'type': 'enum, GC.Spread.Sheets.DataValidation.DataValidationResult',
  762. 'name': 'DataValidationResult',
  763. 'setFunction': setDataValidationResult
  764. },
  765. 'worksheets': {'type': '[]', 'name': 'worksheets', 'setFunction': setSheets, 'properties': worksheetsDef}
  766. }
  767. var Node;
  768. (function (Node) {
  769. Node._map = [];
  770. Node.ELEMENT_NODE = 1;
  771. Node.ATTRIBUTE_NODE = 2;
  772. Node.TEXT_NODE = 3;
  773. Node.CDATA_SECTION_NODE = 4;
  774. Node.ENTITY_REFERENCE_NODE = 5;
  775. Node.ENTITY_NODE = 6;
  776. Node.PROCESSING_INSTRUCTION_NODE = 7;
  777. Node.COMMENT_NODE = 8;
  778. Node.DOCUMENT_NODE = 9;
  779. Node.DOCUMENT_TYPE_NODE = 10;
  780. Node.DOCUMENT_FRAGMENT_NODE = 11;
  781. Node.NOTATION_NODE = 12;
  782. })(Node || (Node = {}));
  783. var SpreadAngularManager = function () {
  784. };
  785. SpreadAngularManager.prototype.setValues = function () {
  786. var self = this;
  787. if (this.valueCatch) {
  788. angular.forEach(this.valueCatch, function (catchObject) {
  789. var target = catchObject.target;
  790. angular.forEach(catchObject.setting, function (propertySet) {
  791. var nodeDef = propertySet.nodeDef;
  792. var value = propertySet.value;
  793. self.setPropertyValue(target, nodeDef, value);
  794. })
  795. })
  796. }
  797. };
  798. SpreadAngularManager.prototype.setBindings = function (scope) {
  799. var parentScope = scope.$parent;
  800. var self = this;
  801. if (this.bindings) {
  802. angular.forEach(this.bindings, function (attBinding) {
  803. if (attBinding.dynamicText) {
  804. var bindingPath = attBinding.dynamicText.substring(2, attBinding.dynamicText.length - 2);
  805. if (!attBinding.target._angularBindingPath) {
  806. attBinding.target._angularBindingPath = {};
  807. }
  808. attBinding.target._angularBindingPath[attBinding.name] = bindingPath;
  809. var bindingPathLowerCase = bindingPath;
  810. if (parentScope[bindingPathLowerCase] === undefined) {
  811. parentScope[bindingPathLowerCase] = self.getPropertyValue(attBinding.target, attBinding.metadata);
  812. } else {
  813. self.setPropertyValue(attBinding.target, attBinding.metadata, parentScope[bindingPathLowerCase]);
  814. }
  815. parentScope.$watch(bindingPath, function (value) {
  816. self.setPropertyValue(attBinding.target, attBinding.metadata, value);
  817. })
  818. }
  819. })
  820. }
  821. };
  822. SpreadAngularManager.prototype.initSpread = function (scope, element) {
  823. var node = element[0];
  824. this._readNodeWithChildren(scope, node, workbookPropertyMap, 'worksheets', false);
  825. };
  826. SpreadAngularManager.prototype._readNodeWithChildren = function (target, node, map, excludeChildren, setValueDirectly) {
  827. var self = this;
  828. if (!setValueDirectly) {
  829. if (!this.valueCatch) {
  830. this.valueCatch = [];
  831. }
  832. var catchObject;
  833. angular.forEach(this.valueCatch, function (catchTmp) {
  834. if (catchTmp.target === target) {
  835. catchObject = catchTmp;
  836. }
  837. });
  838. if (!catchObject) {
  839. catchObject = {
  840. target: target, setting: []
  841. };
  842. this.valueCatch.push(catchObject);
  843. }
  844. }
  845. angular.forEach(node.attributes, function (attNode) {
  846. self._readNode(target, attNode, map, catchObject, setValueDirectly)
  847. });
  848. if (node.childNodes.length > 0) {
  849. angular.forEach(node.childNodes, function (childNode) {
  850. var nodeName = childNode.nodeName.toLowerCase();
  851. nodeName = self.normalizeName(nodeName);
  852. var nodeDef = map[nodeName];
  853. if (!nodeDef || !nodeDef.type) {
  854. return
  855. }
  856. var childTarget;
  857. if (nodeDef.type === 'object') {
  858. childTarget = {}
  859. } else if (nodeDef.type === '[]') {
  860. childTarget = []
  861. } else {
  862. var type = nodeDef.type;
  863. if (type.indexOf('.') > 0) {
  864. var namespaces = type.split('.');
  865. var parent = window[namespaces[0]];
  866. for (var i = 1; i < namespaces.length; i++) {
  867. type = parent[namespaces[i]];
  868. if (!type) {
  869. break;
  870. }
  871. parent = type;
  872. }
  873. } else {
  874. type = GC.Spread.Sheets[nodeDef.type];
  875. }
  876. if (!type) {
  877. return
  878. }
  879. childTarget = new type;
  880. }
  881. if (nodeDef.name === 'worksheets' || nodeDef.name === 'worksheet' || nodeDef.name === 'columns' || nodeDef.name === 'column') {
  882. self._readNodeWithChildren(childTarget, childNode, nodeDef.properties, undefined, false);
  883. } else {
  884. self._readNodeWithChildren(childTarget, childNode, nodeDef.properties, undefined, true);
  885. }
  886. if (setValueDirectly) {
  887. self.setPropertyValue(target, nodeDef, childTarget);
  888. } else {
  889. catchObject.setting.push({
  890. nodeDef: nodeDef, value: childTarget
  891. })
  892. }
  893. })
  894. }
  895. };
  896. SpreadAngularManager.prototype.convertValue = function (value, targetType, converter) {
  897. if (converter) {
  898. return converter(value)
  899. }
  900. if (value === undefined || targetType === undefined) {
  901. return value
  902. }
  903. if (typeof value === 'string') {
  904. value = value.trim();
  905. }
  906. if (targetType.length > 2 && targetType[0] === '[') {
  907. var argType = targetType.substring(1, targetType.length - 2);
  908. if (value.length > 2) {
  909. if (value[0] === '[' && value[value.length - 1] === ']') {
  910. value = value.substring(1, value.length - 2);
  911. }
  912. var partsValue = value.split(',');
  913. var result = [];
  914. for (var i = 0; i < partsValue.length; i++) {
  915. result.push(this.convertValue(partsValue[i], argType, converter));
  916. }
  917. return result;
  918. }
  919. }
  920. switch (targetType) {
  921. case 'string':
  922. return value;
  923. case 'boolean':
  924. if (typeof value === 'boolean') {
  925. return value;
  926. }
  927. if (value.toLowerCase() === 'true') {
  928. return true;
  929. } else if (value.toLowerCase() === 'false') {
  930. return false;
  931. }
  932. return Boolean(value);
  933. case 'number':
  934. return Number(value);
  935. case 'color':
  936. return value;
  937. case '[]':
  938. return value;
  939. }
  940. if (targetType.length > 5 && targetType.substring(0, 5) === 'enum,') {
  941. if (typeof value === 'number' || typeof value === 'string' && parseInt(value) !== undefined && !isNaN(parseInt(value))) {
  942. result = parseInt(value);
  943. } else {
  944. targetType = targetType.substring(5).trim();
  945. var resultType = GC.Spread.Sheets;
  946. if (targetType.indexOf('.') > 0) {
  947. resultType = window;
  948. var parts = targetType.split('.');
  949. for (i = 0; i < parts.length; i++) {
  950. resultType = resultType[parts[i]];
  951. }
  952. } else {
  953. resultType = resultType[targetType];
  954. }
  955. result = resultType[value];
  956. if (result === undefined) {
  957. value = value[0].toUpperCase() + value.substring(1);
  958. result = resultType[value];
  959. }
  960. }
  961. return result;
  962. }
  963. return value;
  964. };
  965. SpreadAngularManager.prototype.normalizeName = function (name) {
  966. if (name.match(/-/)) {
  967. var parts = name.split('-');
  968. name = parts.shift();
  969. angular.forEach(parts, function (p) {
  970. name += p;
  971. })
  972. }
  973. return name;
  974. };
  975. SpreadAngularManager.prototype._readNode = function (target, node, map, catchObject, setValueDirectly) {
  976. var $node = $(node),
  977. value,
  978. name,
  979. path;
  980. switch (node.nodeType) {
  981. case Node.ATTRIBUTE_NODE:
  982. value = $node.val();
  983. break;
  984. case Node.ELEMENT_NODE:
  985. value = $node.text();
  986. break;
  987. default:
  988. return;
  989. }
  990. name = node.nodeName || node.name;
  991. name = name.toLowerCase();
  992. name = this.normalizeName(name);
  993. var metadata = map[name];
  994. if (metadata) {
  995. name = metadata.name;
  996. } else {
  997. return
  998. }
  999. if (!this.hasChildElements(node) && value && value.length > 4 && value.substring(0, 2) === '{{' && value.substring(value.length - 2) === '}}') {
  1000. if (!this.bindings) {
  1001. this.bindings = [];
  1002. }
  1003. this.bindings.push({
  1004. target: target, metadata: metadata, path: name, name: name, dynamicText: value
  1005. });
  1006. return
  1007. }
  1008. if (value.match(/^[^\d]/) && node.nodeType === Node.ATTRIBUTE_NODE && (metadata.changeEvent || metadata.twoWayBinding)) {
  1009. if (!this.bindings) {
  1010. this.bindings = [];
  1011. }
  1012. this.bindings.push({
  1013. target: target, path: (path && path + '.') + name, name: name, expression: value
  1014. })
  1015. } else if (node.nodeType === Node.ATTRIBUTE_NODE) {
  1016. if (setValueDirectly) {
  1017. this.setPropertyValue(target, metadata, value);
  1018. } else {
  1019. catchObject.setting.push({
  1020. nodeDef: metadata, value: value
  1021. });
  1022. }
  1023. }
  1024. };
  1025. SpreadAngularManager.prototype.setPropertyValue = function (target, metadata, value) {
  1026. if (value === undefined) {
  1027. return
  1028. }
  1029. if (target.$scopeObject) {
  1030. target = target.$scopeObject;
  1031. }
  1032. try {
  1033. value = this.convertValue(value, metadata.type, metadata.converter);
  1034. if (metadata.setFunction) {
  1035. if (typeof metadata.setFunction === 'function') {
  1036. metadata.setFunction.call(this, target, metadata.name, value);
  1037. } else {
  1038. this.setPropertyValueCore(target, value, undefined, metadata.setFunction);
  1039. }
  1040. } else {
  1041. this.setPropertyValueCore(target, value, metadata.name);
  1042. target[metadata.name] = value;
  1043. }
  1044. } catch (ex) { //
  1045. }
  1046. };
  1047. SpreadAngularManager.prototype.setPropertyValueCore = function (target, value, propertyName, setFunction) {
  1048. if (propertyName) {
  1049. target[propertyName] = value;
  1050. } else if (setFunction) {
  1051. if (typeof setFunction === 'string') {
  1052. target[setFunction](value);
  1053. } else {
  1054. var functionName = setFunction.name;
  1055. var args = [];
  1056. for (var i = 0; i < setFunction.args.length; i++) {
  1057. if (setFunction.args[i] === '$value-replace$') {
  1058. args[i] = value;
  1059. } else {
  1060. args[i] = setFunction.args[i];
  1061. }
  1062. }
  1063. switch (args.length) {
  1064. case 1:
  1065. target[functionName](args[0]);
  1066. break;
  1067. case 2:
  1068. target[functionName](args[0], args[1]);
  1069. break;
  1070. case 3:
  1071. target[functionName](args[0], args[1], args[2]);
  1072. break;
  1073. case 4:
  1074. target[functionName](args[0], args[1], args[2], args[3]);
  1075. break;
  1076. case 5:
  1077. target[functionName](args[0], args[1], args[2], args[3], args[4]);
  1078. break
  1079. }
  1080. }
  1081. }
  1082. };
  1083. SpreadAngularManager.prototype.getPropertyValue = function (target, metadata) {
  1084. if (target.$scopeObject) {
  1085. target = target.$scopeObject;
  1086. }
  1087. var value = '';
  1088. try {
  1089. if (metadata.getProperties) {
  1090. angular.forEach(metadata.getProperties, function (setProperty) {
  1091. if (value === '') {
  1092. value = this.setPropertyValueCore(target, value, setProperty);
  1093. } else {
  1094. value = value + ',' + this.setPropertyValueCore(target, value, setProperty);
  1095. }
  1096. })
  1097. } else if (metadata.getFunction) {
  1098. if (typeof metadata.getFunction === 'function') {
  1099. return metadata.getFunction.call(this, target, metadata.name);
  1100. }
  1101. value = this.getPropertyValueCore(target, undefined, metadata.getFunction);
  1102. } else {
  1103. value = this.getPropertyValueCore(target, name);
  1104. }
  1105. } catch (ex) { //
  1106. }
  1107. return value
  1108. };
  1109. SpreadAngularManager.prototype.getPropertyValueCore = function (target, propertyName, getFunction) {
  1110. if (propertyName) {
  1111. return target[propertyName]
  1112. } else if (getFunction) {
  1113. if (typeof getFunction === 'string') {
  1114. return target[getFunction]();
  1115. }
  1116. }
  1117. return ''
  1118. };
  1119. SpreadAngularManager.prototype.hasChildElements = function (node) {
  1120. if (!node || !node.childNodes) {
  1121. return false
  1122. }
  1123. var len = node.childNodes.length;
  1124. for (var i = 0; i < len; i++) {
  1125. var child = node.childNodes[i];
  1126. if (child.nodeType === Node.ELEMENT_NODE) {
  1127. return true
  1128. }
  1129. }
  1130. return false
  1131. }
  1132. SpreadAngularManager.angularDerictive = function () {
  1133. return {
  1134. restrict: 'E',
  1135. replace: true,
  1136. transclude: true,
  1137. template: '<div ng-transclude/>',
  1138. scope: {
  1139. //showTabs: '@', // Whether to show the sheet selection tabs.
  1140. //autoFitType: '@'
  1141. },
  1142. // add sheets to this spread
  1143. controller: ['$scope', function () {
  1144. }],
  1145. link: function (scope, element, attrs) {
  1146. var manager = new SpreadAngularManager();
  1147. manager.initSpread(scope, element, attrs);
  1148. // create spread component
  1149. var spread = new GC.Spread.Sheets.Workbook(element[0], {sheetCount: 0});
  1150. var ns = GC.Spread.Sheets;
  1151. var parnetScope = scope.$parent;
  1152. scope.$scopeObject = spread;
  1153. spread.suspendCalcService(true);
  1154. spread.suspendPaint();
  1155. manager.setValues();
  1156. var sheetDefs = spread._sheetDefs;
  1157. var hasDataSourceBind = false;
  1158. if (sheetDefs && sheetDefs.length > 0) {
  1159. for (var i = 0; i < sheetDefs.length; i++) {
  1160. var sheet = sheetDefs[i];
  1161. sheet.suspendEvent();
  1162. //sheet.isPaintSuspended(true);
  1163. //spread.addSheet(i, sheet);
  1164. initSheet(sheet);
  1165. if (sheet._angularDataSource) { // will resume in bindSheet
  1166. hasDataSourceBind = true;
  1167. var dataSourceDeepWatch = true;
  1168. if (sheet.dataSourceDeepWatch !== undefined) {
  1169. dataSourceDeepWatch = sheet.dataSourceDeepWatch;
  1170. }
  1171. var watchSheet = function (sheet1, dataSourceDeepWatch1) {
  1172. parnetScope.$watch(sheet1._angularDataSource, function (newValue, oldValue) {
  1173. bindSheet(sheet1, oldValue, newValue)
  1174. }, dataSourceDeepWatch1);
  1175. }
  1176. watchSheet(sheet, dataSourceDeepWatch);
  1177. }
  1178. sheet.resumeEvent();
  1179. }
  1180. }
  1181. if (!hasDataSourceBind) {
  1182. spread.resumePaint();
  1183. }
  1184. spread.resumeCalcService(false);
  1185. function initSheet(sheet) {
  1186. var hasColumns = sheet._columnDefs && sheet._columnDefs.length > 0;
  1187. if (hasColumns) {
  1188. sheet.setColumnCount(sheet._columnDefs.length);
  1189. for (var cIndex = 0; cIndex < sheet._columnDefs.length; cIndex++) {
  1190. sheet._columnDefs[cIndex].attach(sheet, sheet.getRange(-1, cIndex, -1, 1), cIndex);
  1191. }
  1192. }
  1193. sheet.bind(ns.Events.ValidationError, function (event, data) {
  1194. if (spread._angularDataValidationResult !== undefined) {
  1195. data.validationResult = spread._angularDataValidationResult;
  1196. } else {
  1197. data.validationResult = ns.DataValidation.DataValidationResult.discard; //restore original value
  1198. }
  1199. });
  1200. sheet.bind(ns.Events.ColumnWidthChanged, function (event, data) {
  1201. var sheet = data.sheet;
  1202. var colList = data.colList;
  1203. for (var col = 0; col < colList.length; col++) {
  1204. var columnWrapper = sheet._columnDefs[colList[col]];
  1205. var bindingPath = columnWrapper._angularBindingPath && columnWrapper._angularBindingPath['width'];
  1206. if (bindingPath) {
  1207. parnetScope[bindingPath] = sheet.getColumnWidth(colList[col]);
  1208. }
  1209. }
  1210. parnetScope.$apply();
  1211. });
  1212. sheet.bind(ns.Events.SheetNameChanged, function (event, data) {
  1213. var bindingPath = sheet._angularBindingPath && sheet._angularBindingPath['name'];
  1214. if (bindingPath) {
  1215. parnetScope[bindingPath] = data.newValue;
  1216. parnetScope.$apply();
  1217. }
  1218. })
  1219. sheet.bind(ns.Events.UserZooming, function (event, data) {
  1220. var bindingPath = sheet._angularBindingPath && sheet._angularBindingPath['zoom'];
  1221. if (bindingPath) {
  1222. parnetScope[bindingPath] = data.newZoomFactor;
  1223. parnetScope.$apply();
  1224. }
  1225. })
  1226. manager.setBindings(scope);
  1227. }
  1228. // bind the sheet
  1229. function bindSheet(sheet, oldDataSource, newDataSource) {
  1230. var spread = sheet.getParent();
  1231. if (!spread.isPaintSuspended()) {
  1232. spread.suspendPaint();
  1233. }
  1234. if (newDataSource) {
  1235. //If datasource changed.
  1236. if (newDataSource !== sheet.getDataSource()) {
  1237. // bind grid
  1238. var hasColumns = sheet._columnDefs && sheet._columnDefs.length > 0;
  1239. if (hasColumns) {
  1240. sheet.autoGenerateColumns = false;
  1241. sheet.setDataSource(newDataSource, false);
  1242. sheet.setColumnCount(sheet._columnDefs.length);
  1243. for (var col = 0; col < sheet._columnDefs.length; col++) {
  1244. bindColumn(sheet, col);
  1245. }
  1246. } else {
  1247. var colWidths = getColWidths(sheet);
  1248. sheet.autoGenerateColumns = true;
  1249. sheet.setDataSource(newDataSource, false);
  1250. var rowIndex, colHeaderAutoTextIndex = sheet.options.colHeaderAutoTextIndex;
  1251. if (colHeaderAutoTextIndex < 0) {
  1252. rowIndex = sheet.getRowCount(ns.SheetArea.colHeader) - 1;
  1253. } else {
  1254. rowIndex = colHeaderAutoTextIndex;
  1255. }
  1256. for (col = 0; col < sheet.getColumnCount(); col++) {
  1257. var header = sheet.getValue(rowIndex, col, ns.SheetArea.colHeader);
  1258. if (header.indexOf('$$') === 0) { // remove columns bound to work variables
  1259. sheet.deleteColumns(col, 1);
  1260. col--;
  1261. }
  1262. }
  1263. setColWidths(sheet, colWidths);
  1264. }
  1265. } else if (newDataSource && oldDataSource && newDataSource.length !== oldDataSource.length) {
  1266. //If datasource is not changed, but datasource items changed.
  1267. sheet.setRowCountCore(newDataSource.length);
  1268. }
  1269. } else if (oldDataSource) {
  1270. sheet.setDataSource(null, true);
  1271. }
  1272. spread.resumePaint();
  1273. }
  1274. // add a bound column to the sheet
  1275. function bindColumn(sheet, index) {
  1276. var columnWraper = sheet._columnDefs[index];
  1277. // bind column
  1278. if (columnWraper.dataField || columnWraper.headerText) {
  1279. sheet.bindColumn(index, {
  1280. name: columnWraper.dataField,
  1281. displayName: columnWraper.headerText
  1282. });
  1283. }
  1284. columnWraper.updata();
  1285. }
  1286. // save and restore column widths after re-binding
  1287. function getColWidths(sheet) {
  1288. var arr = [];
  1289. for (var i = 0; i < sheet.getColumnCount(); i++) {
  1290. arr.push(sheet.getColumnWidth(i));
  1291. }
  1292. return arr;
  1293. }
  1294. function setColWidths(sheet, colWidths) {
  1295. if (sheet.getColumnCount() === colWidths.length) {
  1296. for (var i = 0; i < sheet.getColumnCount(); i++) {
  1297. sheet.setColumnWidth(i, colWidths[i]);
  1298. }
  1299. }
  1300. }
  1301. }
  1302. }
  1303. }
  1304. m.directive('gcSpreadSheets', function () {
  1305. return SpreadAngularManager.angularDerictive();
  1306. });
  1307. })();