@ezeep/ezeep-js 1.0.139 → 1.0.140

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,5 +17,5 @@ const patchBrowser = () => {
17
17
 
18
18
  patchBrowser().then(options => {
19
19
  appGlobals.globalScripts();
20
- return index.bootstrapLazy([["ezp-auth_12.cjs",[[1,"ezp-printing",{"clientid":[1],"redirecturi":[1],"filename":[1],"fileurl":[1],"filetype":[1],"custom":[4],"hidelogin":[4],"authapihosturl":[1],"printapihosturl":[1],"theme":[1],"appearance":[1],"printOpen":[32],"authOpen":[32],"open":[64]},[[0,"printCancel","listenPrintCancel"],[0,"printSubmit","listenPrintSubmit"],[0,"authCancel","listenAuthCancel"],[0,"authShow","listenAuthShow"],[0,"printShow","listenPrintShow"]]],[1,"ezp-printer-selection",{"clientID":[1,"client-i-d"],"redirectURI":[1,"redirect-u-r-i"],"filename":[1],"fileurl":[1],"filetype":[1],"loading":[32],"options":[32],"printInProgress":[32],"userMenuOpen":[32],"userName":[32],"printers":[32],"selectedPrinter":[32],"printerConfig":[32],"selectedProperties":[32],"previouslySelectedProperties":[32]},[[0,"selectSelection","listenSelectSelection"],[0,"stepperChanged","listenStepperChanged"],[0,"userMenuClosure","listenUserMenuClosure"],[0,"logoutEmitter","listenLogout"]]],[1,"ezp-auth",{"clientID":[1025,"client-i-d"],"redirectURI":[1025,"redirect-u-r-i"],"hidelogin":[4],"auth":[32],"authURI":[32],"accessToken":[32]}],[1,"ezp-user-menu",{"name":[1],"open":[1028]}],[1,"ezp-select",{"icon":[1],"label":[1],"optionFlow":[1,"option-flow"],"options":[16],"placeholder":[1],"preSelected":[8,"pre-selected"],"toggleFlow":[1,"toggle-flow"],"expanded":[32],"selected":[32]}],[1,"ezp-stepper",{"icon":[1],"label":[1],"max":[2],"min":[2],"canDecrease":[32],"canIncrease":[32],"focused":[32],"value":[32]}],[1,"ezp-progress",{"status":[1]}],[1,"ezp-text-button",{"blank":[4],"disabled":[4],"href":[1],"level":[1],"label":[1],"type":[1]}],[1,"ezp-icon-button",{"blank":[4],"disabled":[4],"href":[1],"icon":[1],"level":[1],"type":[1]}],[1,"ezp-backdrop",{"visible":[1028]},[[0,"animationend","listenAnimationEnd"]]],[1,"ezp-icon",{"name":[1],"size":[1]}],[1,"ezp-label",{"ellipsis":[4],"level":[1],"noWrap":[4,"no-wrap"],"text":[1],"weight":[1]}]]]], options);
20
+ return index.bootstrapLazy([["ezp-auth_12.cjs",[[1,"ezp-printing",{"clientid":[1],"redirecturi":[1],"filename":[1],"fileurl":[1],"filetype":[1],"custom":[4],"hidelogin":[4],"authapihosturl":[1],"printapihosturl":[1],"theme":[1],"fileid":[1],"appearance":[1],"printOpen":[32],"authOpen":[32],"open":[64]},[[0,"printCancel","listenPrintCancel"],[0,"printSubmit","listenPrintSubmit"],[0,"authCancel","listenAuthCancel"],[0,"authShow","listenAuthShow"],[0,"printShow","listenPrintShow"]]],[1,"ezp-printer-selection",{"clientID":[1,"client-i-d"],"redirectURI":[1,"redirect-u-r-i"],"filename":[1],"fileurl":[1],"filetype":[1],"fileid":[1],"loading":[32],"options":[32],"printInProgress":[32],"userMenuOpen":[32],"userName":[32],"printers":[32],"selectedPrinter":[32],"printerConfig":[32],"selectedPrinterConfig":[32],"selectedProperties":[32],"previouslySelectedProperties":[32]},[[0,"selectSelection","listenSelectSelection"],[0,"stepperChanged","listenStepperChanged"],[0,"userMenuClosure","listenUserMenuClosure"],[0,"logoutEmitter","listenLogout"]]],[1,"ezp-auth",{"clientID":[1025,"client-i-d"],"redirectURI":[1025,"redirect-u-r-i"],"hidelogin":[4],"auth":[32],"authURI":[32],"accessToken":[32]}],[1,"ezp-user-menu",{"name":[1],"open":[1028]}],[1,"ezp-select",{"icon":[1],"label":[1],"optionFlow":[1,"option-flow"],"options":[16],"placeholder":[1],"preSelected":[8,"pre-selected"],"toggleFlow":[1,"toggle-flow"],"expanded":[32],"selected":[32]}],[1,"ezp-stepper",{"icon":[1],"label":[1],"max":[2],"min":[2],"canDecrease":[32],"canIncrease":[32],"focused":[32],"value":[32]}],[1,"ezp-progress",{"status":[1]}],[1,"ezp-text-button",{"blank":[4],"disabled":[4],"href":[1],"level":[1],"label":[1],"type":[1]}],[1,"ezp-icon-button",{"blank":[4],"disabled":[4],"href":[1],"icon":[1],"level":[1],"type":[1]}],[1,"ezp-backdrop",{"visible":[1028]},[[0,"animationend","listenAnimationEnd"]]],[1,"ezp-icon",{"name":[1],"size":[1]}],[1,"ezp-label",{"ellipsis":[4],"level":[1],"noWrap":[4,"no-wrap"],"text":[1],"weight":[1]}]]]], options);
21
21
  });
@@ -4152,7 +4152,17 @@ class EzpPrintService {
4152
4152
  'Content-Type': 'application/json',
4153
4153
  },
4154
4154
  body: JSON.stringify(Object.assign(Object.assign(Object.assign({ fileurl: fileUrl, type: fileType, printerid: printerID }, (filename && { alias: filename })), (printAndDelete && { printanddelete: printAndDelete })), { properties })),
4155
- }).then((response) => response.json());
4155
+ });
4156
+ }
4157
+ printByFileID(accessToken, fileID, fileType, printerID, properties, filename, printAndDelete) {
4158
+ return fetch(`https://${this.printingApi}/sfapi/Print/`, {
4159
+ method: 'POST',
4160
+ headers: {
4161
+ Authorization: 'Bearer ' + accessToken,
4162
+ 'Content-Type': 'application/json',
4163
+ },
4164
+ body: JSON.stringify(Object.assign(Object.assign(Object.assign({ fileid: fileID, type: fileType, printerid: printerID }, (filename && { alias: filename })), (printAndDelete && { printanddelete: printAndDelete })), { properties })),
4165
+ });
4156
4166
  }
4157
4167
  }
4158
4168
  const printStore = createStore({
@@ -4160,6 +4170,12 @@ const printStore = createStore({
4160
4170
  jobID: '',
4161
4171
  printFinished: false,
4162
4172
  printApiHostUrl: '',
4173
+ printerProperties: {},
4174
+ fileID: '',
4175
+ fileUrl: '',
4176
+ fileType: '',
4177
+ printerID: '',
4178
+ fileName: ''
4163
4179
  });
4164
4180
 
4165
4181
  class EzpUserService {
@@ -4294,7 +4310,7 @@ let EzpPrinterSelection = class {
4294
4310
  this.selectedProperties = {
4295
4311
  paper: '',
4296
4312
  paperid: '',
4297
- color: '',
4313
+ color: false,
4298
4314
  duplex: false,
4299
4315
  duplexmode: '',
4300
4316
  orientation: '',
@@ -4304,7 +4320,7 @@ let EzpPrinterSelection = class {
4304
4320
  this.previouslySelectedProperties = {
4305
4321
  paper: '',
4306
4322
  paperid: '',
4307
- color: '',
4323
+ color: false,
4308
4324
  duplex: false,
4309
4325
  duplexmode: '',
4310
4326
  orientation: '',
@@ -4322,39 +4338,88 @@ let EzpPrinterSelection = class {
4322
4338
  };
4323
4339
  /** Description... */
4324
4340
  this.handlePrint = () => {
4341
+ const validateData = (data) => {
4342
+ if (data.jobstatus === 0) {
4343
+ this.printInProgress = false;
4344
+ return true;
4345
+ }
4346
+ return false;
4347
+ };
4348
+ const POLL_INTERVAL = 2000;
4325
4349
  this.printInProgress = true;
4326
- this.printService
4327
- .printFileByUrl(authStore.state.accessToken, this.fileurl, this.filetype, this.selectedPrinter.id,
4328
4350
  // we have to initialse this obj with empty strings to display the select component
4329
4351
  // but don't want to send any attributes with empty strings to the API
4330
- removeEmptyStrings(this.selectedProperties), this.filename)
4331
- .then((data) => {
4332
- if (data.jobid) {
4333
- printStore.state.jobID = data.jobid;
4334
- const POLL_INTERVAL = 2000;
4335
- const validateData = (data) => {
4336
- if (data.jobstatus === 0) {
4352
+ removeEmptyStrings(this.selectedProperties);
4353
+ // put it in store for further use
4354
+ printStore.state.fileUrl = this.fileurl;
4355
+ printStore.state.fileID = this.fileid;
4356
+ printStore.state.fileType = this.filetype;
4357
+ printStore.state.printerID = this.selectedPrinter.id;
4358
+ printStore.state.printerProperties = this.selectedProperties;
4359
+ printStore.state.fileName = this.filename;
4360
+ if (this.fileurl) {
4361
+ this.printService
4362
+ .printFileByUrl(authStore.state.accessToken, this.fileurl, this.filetype, this.selectedPrinter.id, this.selectedProperties, this.filename)
4363
+ .then((response) => {
4364
+ if (response.status === 412) {
4365
+ response.json().then(data => this.fileid = data.fileid);
4366
+ this.printService.printByFileID(authStore.state.accessToken, this.fileid, this.filetype, this.selectedPrinter.id, this.selectedProperties, this.filename).finally(() => this.printInProgress = false);
4367
+ }
4368
+ else {
4369
+ return response.json();
4370
+ }
4371
+ })
4372
+ .then((data) => {
4373
+ if (data.jobid) {
4374
+ printStore.state.jobID = data.jobid;
4375
+ poll({
4376
+ fn: this.printService.getPrintStatus,
4377
+ validate: validateData,
4378
+ interval: POLL_INTERVAL,
4379
+ maxAttempts: 10,
4380
+ })
4381
+ .then(data)
4382
+ .catch((err) => {
4383
+ console.warn(err);
4337
4384
  this.printInProgress = false;
4338
- return true;
4339
- }
4340
- return false;
4341
- };
4342
- poll({
4343
- fn: this.printService.getPrintStatus,
4344
- validate: validateData,
4345
- interval: POLL_INTERVAL,
4346
- maxAttempts: 10,
4347
- })
4348
- .then(data)
4349
- .catch((err) => {
4350
- console.warn(err);
4385
+ });
4386
+ }
4387
+ else {
4351
4388
  this.printInProgress = false;
4352
- });
4353
- }
4354
- else {
4389
+ }
4390
+ })
4391
+ .catch(error => {
4392
+ console.log(error);
4355
4393
  this.printInProgress = false;
4356
- }
4357
- });
4394
+ });
4395
+ }
4396
+ else if (this.fileid) {
4397
+ this.printService.printByFileID(authStore.state.accessToken, this.fileid, this.filetype, this.selectedPrinter.id, this.selectedProperties, this.filename)
4398
+ .then((response) => response.json())
4399
+ .then((data) => {
4400
+ if (data.jobid) {
4401
+ printStore.state.jobID = data.jobid;
4402
+ poll({
4403
+ fn: this.printService.getPrintStatus,
4404
+ validate: validateData,
4405
+ interval: POLL_INTERVAL,
4406
+ maxAttempts: 10,
4407
+ })
4408
+ .then(data)
4409
+ .catch((err) => {
4410
+ console.warn(err);
4411
+ this.printInProgress = false;
4412
+ });
4413
+ }
4414
+ else {
4415
+ this.printInProgress = false;
4416
+ }
4417
+ })
4418
+ .catch(error => {
4419
+ console.log(error);
4420
+ this.printInProgress = false;
4421
+ });
4422
+ }
4358
4423
  localStorage.setItem('properties', JSON.stringify(this.selectedProperties));
4359
4424
  localStorage.setItem('printer', JSON.stringify(this.selectedPrinter));
4360
4425
  localStorage.setItem('previouslySelectedProperties', JSON.stringify(this.previouslySelectedProperties));
@@ -4402,11 +4467,14 @@ let EzpPrinterSelection = class {
4402
4467
  this.userName = userStore.state.user.display_name;
4403
4468
  });
4404
4469
  }
4405
- setSelectedProperties(eventDetails) {
4470
+ async setSelectedProperties(eventDetails) {
4406
4471
  switch (eventDetails.type) {
4407
4472
  case 'printer':
4408
4473
  this.selectedPrinter.id = eventDetails.id;
4409
4474
  this.selectedPrinter.name = eventDetails.title;
4475
+ await this.printService.getPrinterProperties(authStore.state.accessToken, this.selectedPrinter.id).then(data => this.selectedPrinterConfig = data[0]);
4476
+ console.log('selected printer config:');
4477
+ console.log(this.selectedPrinterConfig);
4410
4478
  break;
4411
4479
  case 'color':
4412
4480
  this.selectedProperties.color = !!eventDetails.id;
@@ -4458,7 +4526,8 @@ let EzpPrinterSelection = class {
4458
4526
  await this.printService
4459
4527
  .getAllPrinterProperties(authStore.state.accessToken)
4460
4528
  .then((printerConfig) => {
4461
- this.printerConfig = printerConfig[0];
4529
+ this.printerConfig = printerConfig;
4530
+ console.log(this.printerConfig);
4462
4531
  });
4463
4532
  this.loading = false;
4464
4533
  }
@@ -4475,7 +4544,7 @@ let EzpPrinterSelection = class {
4475
4544
  ? printer.location
4476
4545
  : i18next.t('printer_selection.unknown_location'),
4477
4546
  type: 'printer',
4478
- })), preSelected: this.selectedPrinter.name })), index.h("div", { id: "options" }, index.h("ezp-select", { label: i18next.t('printer_selection.color'), icon: "color", placeholder: i18next.t('printer_selection.select_color'), toggleFlow: "horizontal", options: this.printerConfig.Color
4547
+ })), preSelected: this.selectedPrinter.name })), index.h("div", { id: "options" }, index.h("ezp-select", { label: i18next.t('printer_selection.color'), icon: "color", placeholder: i18next.t('printer_selection.select_color'), toggleFlow: "horizontal", options: this.selectedPrinterConfig.Color
4479
4548
  ? [
4480
4549
  {
4481
4550
  id: 1,
@@ -4497,24 +4566,24 @@ let EzpPrinterSelection = class {
4497
4566
  meta: '',
4498
4567
  type: 'color',
4499
4568
  },
4500
- ], preSelected: this.previouslySelectedProperties.color }), index.h("ezp-select", { label: i18next.t('printer_selection.orientation'), icon: "orientation", placeholder: i18next.t('printer_selection.select_orientation'), toggleFlow: "horizontal", options: this.printerConfig.OrientationsSupported.map((orientation, index) => ({
4569
+ ], preSelected: this.previouslySelectedProperties.color }), index.h("ezp-select", { label: i18next.t('printer_selection.orientation'), icon: "orientation", placeholder: i18next.t('printer_selection.select_orientation'), toggleFlow: "horizontal", options: this.selectedPrinterConfig.OrientationsSupported.map((orientation, index) => ({
4501
4570
  id: index,
4502
4571
  title: i18next.t(`printer_selection.orientation_${orientation}`),
4503
4572
  meta: '',
4504
4573
  type: 'orientation',
4505
- })), preSelected: this.previouslySelectedProperties.orientation }), index.h("ezp-select", { label: i18next.t('printer_selection.size'), icon: "size", placeholder: i18next.t('printer_selection.select_size'), toggleFlow: "horizontal", optionFlow: "horizontal", options: this.printerConfig.PaperFormats.map((format) => ({
4574
+ })), preSelected: this.previouslySelectedProperties.orientation }), index.h("ezp-select", { label: i18next.t('printer_selection.size'), icon: "size", placeholder: i18next.t('printer_selection.select_size'), toggleFlow: "horizontal", optionFlow: "horizontal", options: this.selectedPrinterConfig.PaperFormats.map((format) => ({
4506
4575
  id: format.Id,
4507
4576
  title: format.Name,
4508
4577
  meta: `${format.XRes} x ${format.YRes}`,
4509
4578
  type: 'format',
4510
- })), preSelected: this.previouslySelectedProperties.paper }), index.h("ezp-select", { label: i18next.t('printer_selection.quality'), icon: "quality", toggleFlow: "horizontal", options: this.printerConfig.Resolutions.map((option, index) => ({
4579
+ })), preSelected: this.previouslySelectedProperties.paper }), index.h("ezp-select", { label: i18next.t('printer_selection.quality'), icon: "quality", toggleFlow: "horizontal", options: this.selectedPrinterConfig.Resolutions.map((option, index) => ({
4511
4580
  id: index,
4512
4581
  title: option,
4513
4582
  meta: '',
4514
4583
  type: 'quality',
4515
4584
  })), preSelected: !this.previouslySelectedProperties.resolution
4516
- ? this.printerConfig.Resolutions[0]
4517
- : this.previouslySelectedProperties.resolution }), this.printerConfig.DuplexSupported ? (index.h("ezp-select", { label: i18next.t('printer_selection.duplex'), icon: "duplex", toggleFlow: "horizontal", options: this.duplexOptions.map((option) => ({
4585
+ ? this.selectedPrinterConfig.Resolutions[0]
4586
+ : this.previouslySelectedProperties.resolution }), this.selectedPrinterConfig.DuplexSupported ? (index.h("ezp-select", { label: i18next.t('printer_selection.duplex'), icon: "duplex", toggleFlow: "horizontal", options: this.duplexOptions.map((option) => ({
4518
4587
  id: option.id,
4519
4588
  title: option.title,
4520
4589
  meta: '',
@@ -4625,7 +4694,7 @@ let EzpPrinting = class {
4625
4694
  *
4626
4695
  */
4627
4696
  render() {
4628
- return (index.h(index.Host, { class: `${userStore.state.theme} ${userStore.state.appearance}` }, this.authOpen ? (index.h("ezp-auth", { clientID: this.clientid, redirectURI: this.redirecturi, hidelogin: this.hidelogin })) : this.printOpen ? (index.h("ezp-printer-selection", { clientID: this.clientid, redirectURI: this.redirecturi, filename: this.filename, fileurl: this.fileurl, filetype: this.filetype })) : this.custom ? (index.h("slot", null)) : (index.h("ezp-icon-button", { id: "print-trigger", icon: "printer", slot: "trigger", type: "button", onClick: () => this.open() }))));
4697
+ return (index.h(index.Host, { class: `${userStore.state.theme} ${userStore.state.appearance}` }, this.authOpen ? (index.h("ezp-auth", { clientID: this.clientid, redirectURI: this.redirecturi, hidelogin: this.hidelogin })) : this.printOpen ? (index.h("ezp-printer-selection", { clientID: this.clientid, redirectURI: this.redirecturi, filename: this.filename, fileurl: this.fileurl, filetype: this.filetype, fileid: this.fileid })) : this.custom ? (index.h("slot", null)) : (index.h("ezp-icon-button", { id: "print-trigger", icon: "printer", slot: "trigger", type: "button", onClick: () => this.open() }))));
4629
4698
  }
4630
4699
  };
4631
4700
  EzpPrinting.style = ezpPrintingCss;
@@ -16,7 +16,7 @@ const defineCustomElements = (win, options) => {
16
16
  if (typeof window === 'undefined') return Promise.resolve();
17
17
  return patchEsm().then(() => {
18
18
  appGlobals.globalScripts();
19
- return index.bootstrapLazy([["ezp-auth_12.cjs",[[1,"ezp-printing",{"clientid":[1],"redirecturi":[1],"filename":[1],"fileurl":[1],"filetype":[1],"custom":[4],"hidelogin":[4],"authapihosturl":[1],"printapihosturl":[1],"theme":[1],"appearance":[1],"printOpen":[32],"authOpen":[32],"open":[64]},[[0,"printCancel","listenPrintCancel"],[0,"printSubmit","listenPrintSubmit"],[0,"authCancel","listenAuthCancel"],[0,"authShow","listenAuthShow"],[0,"printShow","listenPrintShow"]]],[1,"ezp-printer-selection",{"clientID":[1,"client-i-d"],"redirectURI":[1,"redirect-u-r-i"],"filename":[1],"fileurl":[1],"filetype":[1],"loading":[32],"options":[32],"printInProgress":[32],"userMenuOpen":[32],"userName":[32],"printers":[32],"selectedPrinter":[32],"printerConfig":[32],"selectedProperties":[32],"previouslySelectedProperties":[32]},[[0,"selectSelection","listenSelectSelection"],[0,"stepperChanged","listenStepperChanged"],[0,"userMenuClosure","listenUserMenuClosure"],[0,"logoutEmitter","listenLogout"]]],[1,"ezp-auth",{"clientID":[1025,"client-i-d"],"redirectURI":[1025,"redirect-u-r-i"],"hidelogin":[4],"auth":[32],"authURI":[32],"accessToken":[32]}],[1,"ezp-user-menu",{"name":[1],"open":[1028]}],[1,"ezp-select",{"icon":[1],"label":[1],"optionFlow":[1,"option-flow"],"options":[16],"placeholder":[1],"preSelected":[8,"pre-selected"],"toggleFlow":[1,"toggle-flow"],"expanded":[32],"selected":[32]}],[1,"ezp-stepper",{"icon":[1],"label":[1],"max":[2],"min":[2],"canDecrease":[32],"canIncrease":[32],"focused":[32],"value":[32]}],[1,"ezp-progress",{"status":[1]}],[1,"ezp-text-button",{"blank":[4],"disabled":[4],"href":[1],"level":[1],"label":[1],"type":[1]}],[1,"ezp-icon-button",{"blank":[4],"disabled":[4],"href":[1],"icon":[1],"level":[1],"type":[1]}],[1,"ezp-backdrop",{"visible":[1028]},[[0,"animationend","listenAnimationEnd"]]],[1,"ezp-icon",{"name":[1],"size":[1]}],[1,"ezp-label",{"ellipsis":[4],"level":[1],"noWrap":[4,"no-wrap"],"text":[1],"weight":[1]}]]]], options);
19
+ return index.bootstrapLazy([["ezp-auth_12.cjs",[[1,"ezp-printing",{"clientid":[1],"redirecturi":[1],"filename":[1],"fileurl":[1],"filetype":[1],"custom":[4],"hidelogin":[4],"authapihosturl":[1],"printapihosturl":[1],"theme":[1],"fileid":[1],"appearance":[1],"printOpen":[32],"authOpen":[32],"open":[64]},[[0,"printCancel","listenPrintCancel"],[0,"printSubmit","listenPrintSubmit"],[0,"authCancel","listenAuthCancel"],[0,"authShow","listenAuthShow"],[0,"printShow","listenPrintShow"]]],[1,"ezp-printer-selection",{"clientID":[1,"client-i-d"],"redirectURI":[1,"redirect-u-r-i"],"filename":[1],"fileurl":[1],"filetype":[1],"fileid":[1],"loading":[32],"options":[32],"printInProgress":[32],"userMenuOpen":[32],"userName":[32],"printers":[32],"selectedPrinter":[32],"printerConfig":[32],"selectedPrinterConfig":[32],"selectedProperties":[32],"previouslySelectedProperties":[32]},[[0,"selectSelection","listenSelectSelection"],[0,"stepperChanged","listenStepperChanged"],[0,"userMenuClosure","listenUserMenuClosure"],[0,"logoutEmitter","listenLogout"]]],[1,"ezp-auth",{"clientID":[1025,"client-i-d"],"redirectURI":[1025,"redirect-u-r-i"],"hidelogin":[4],"auth":[32],"authURI":[32],"accessToken":[32]}],[1,"ezp-user-menu",{"name":[1],"open":[1028]}],[1,"ezp-select",{"icon":[1],"label":[1],"optionFlow":[1,"option-flow"],"options":[16],"placeholder":[1],"preSelected":[8,"pre-selected"],"toggleFlow":[1,"toggle-flow"],"expanded":[32],"selected":[32]}],[1,"ezp-stepper",{"icon":[1],"label":[1],"max":[2],"min":[2],"canDecrease":[32],"canIncrease":[32],"focused":[32],"value":[32]}],[1,"ezp-progress",{"status":[1]}],[1,"ezp-text-button",{"blank":[4],"disabled":[4],"href":[1],"level":[1],"label":[1],"type":[1]}],[1,"ezp-icon-button",{"blank":[4],"disabled":[4],"href":[1],"icon":[1],"level":[1],"type":[1]}],[1,"ezp-backdrop",{"visible":[1028]},[[0,"animationend","listenAnimationEnd"]]],[1,"ezp-icon",{"name":[1],"size":[1]}],[1,"ezp-label",{"ellipsis":[4],"level":[1],"noWrap":[4,"no-wrap"],"text":[1],"weight":[1]}]]]], options);
20
20
  });
21
21
  };
22
22
 
@@ -35,7 +35,7 @@ export class EzpPrinterSelection {
35
35
  this.selectedProperties = {
36
36
  paper: '',
37
37
  paperid: '',
38
- color: '',
38
+ color: false,
39
39
  duplex: false,
40
40
  duplexmode: '',
41
41
  orientation: '',
@@ -45,7 +45,7 @@ export class EzpPrinterSelection {
45
45
  this.previouslySelectedProperties = {
46
46
  paper: '',
47
47
  paperid: '',
48
- color: '',
48
+ color: false,
49
49
  duplex: false,
50
50
  duplexmode: '',
51
51
  orientation: '',
@@ -63,39 +63,88 @@ export class EzpPrinterSelection {
63
63
  };
64
64
  /** Description... */
65
65
  this.handlePrint = () => {
66
+ const validateData = (data) => {
67
+ if (data.jobstatus === 0) {
68
+ this.printInProgress = false;
69
+ return true;
70
+ }
71
+ return false;
72
+ };
73
+ const POLL_INTERVAL = 2000;
66
74
  this.printInProgress = true;
67
- this.printService
68
- .printFileByUrl(authStore.state.accessToken, this.fileurl, this.filetype, this.selectedPrinter.id,
69
75
  // we have to initialse this obj with empty strings to display the select component
70
76
  // but don't want to send any attributes with empty strings to the API
71
- removeEmptyStrings(this.selectedProperties), this.filename)
72
- .then((data) => {
73
- if (data.jobid) {
74
- printStore.state.jobID = data.jobid;
75
- const POLL_INTERVAL = 2000;
76
- const validateData = (data) => {
77
- if (data.jobstatus === 0) {
77
+ removeEmptyStrings(this.selectedProperties);
78
+ // put it in store for further use
79
+ printStore.state.fileUrl = this.fileurl;
80
+ printStore.state.fileID = this.fileid;
81
+ printStore.state.fileType = this.filetype;
82
+ printStore.state.printerID = this.selectedPrinter.id;
83
+ printStore.state.printerProperties = this.selectedProperties;
84
+ printStore.state.fileName = this.filename;
85
+ if (this.fileurl) {
86
+ this.printService
87
+ .printFileByUrl(authStore.state.accessToken, this.fileurl, this.filetype, this.selectedPrinter.id, this.selectedProperties, this.filename)
88
+ .then((response) => {
89
+ if (response.status === 412) {
90
+ response.json().then(data => this.fileid = data.fileid);
91
+ this.printService.printByFileID(authStore.state.accessToken, this.fileid, this.filetype, this.selectedPrinter.id, this.selectedProperties, this.filename).finally(() => this.printInProgress = false);
92
+ }
93
+ else {
94
+ return response.json();
95
+ }
96
+ })
97
+ .then((data) => {
98
+ if (data.jobid) {
99
+ printStore.state.jobID = data.jobid;
100
+ poll({
101
+ fn: this.printService.getPrintStatus,
102
+ validate: validateData,
103
+ interval: POLL_INTERVAL,
104
+ maxAttempts: 10,
105
+ })
106
+ .then(data)
107
+ .catch((err) => {
108
+ console.warn(err);
78
109
  this.printInProgress = false;
79
- return true;
80
- }
81
- return false;
82
- };
83
- poll({
84
- fn: this.printService.getPrintStatus,
85
- validate: validateData,
86
- interval: POLL_INTERVAL,
87
- maxAttempts: 10,
88
- })
89
- .then(data)
90
- .catch((err) => {
91
- console.warn(err);
110
+ });
111
+ }
112
+ else {
92
113
  this.printInProgress = false;
93
- });
94
- }
95
- else {
114
+ }
115
+ })
116
+ .catch(error => {
117
+ console.log(error);
96
118
  this.printInProgress = false;
97
- }
98
- });
119
+ });
120
+ }
121
+ else if (this.fileid) {
122
+ this.printService.printByFileID(authStore.state.accessToken, this.fileid, this.filetype, this.selectedPrinter.id, this.selectedProperties, this.filename)
123
+ .then((response) => response.json())
124
+ .then((data) => {
125
+ if (data.jobid) {
126
+ printStore.state.jobID = data.jobid;
127
+ poll({
128
+ fn: this.printService.getPrintStatus,
129
+ validate: validateData,
130
+ interval: POLL_INTERVAL,
131
+ maxAttempts: 10,
132
+ })
133
+ .then(data)
134
+ .catch((err) => {
135
+ console.warn(err);
136
+ this.printInProgress = false;
137
+ });
138
+ }
139
+ else {
140
+ this.printInProgress = false;
141
+ }
142
+ })
143
+ .catch(error => {
144
+ console.log(error);
145
+ this.printInProgress = false;
146
+ });
147
+ }
99
148
  localStorage.setItem('properties', JSON.stringify(this.selectedProperties));
100
149
  localStorage.setItem('printer', JSON.stringify(this.selectedPrinter));
101
150
  localStorage.setItem('previouslySelectedProperties', JSON.stringify(this.previouslySelectedProperties));
@@ -143,11 +192,14 @@ export class EzpPrinterSelection {
143
192
  this.userName = userStore.state.user.display_name;
144
193
  });
145
194
  }
146
- setSelectedProperties(eventDetails) {
195
+ async setSelectedProperties(eventDetails) {
147
196
  switch (eventDetails.type) {
148
197
  case 'printer':
149
198
  this.selectedPrinter.id = eventDetails.id;
150
199
  this.selectedPrinter.name = eventDetails.title;
200
+ await this.printService.getPrinterProperties(authStore.state.accessToken, this.selectedPrinter.id).then(data => this.selectedPrinterConfig = data[0]);
201
+ console.log('selected printer config:');
202
+ console.log(this.selectedPrinterConfig);
151
203
  break;
152
204
  case 'color':
153
205
  this.selectedProperties.color = !!eventDetails.id;
@@ -201,7 +253,8 @@ export class EzpPrinterSelection {
201
253
  await this.printService
202
254
  .getAllPrinterProperties(authStore.state.accessToken)
203
255
  .then((printerConfig) => {
204
- this.printerConfig = printerConfig[0];
256
+ this.printerConfig = printerConfig;
257
+ console.log(this.printerConfig);
205
258
  });
206
259
  this.loading = false;
207
260
  }
@@ -229,7 +282,7 @@ export class EzpPrinterSelection {
229
282
  type: 'printer',
230
283
  })), preSelected: this.selectedPrinter.name })),
231
284
  h("div", { id: "options" },
232
- h("ezp-select", { label: i18next.t('printer_selection.color'), icon: "color", placeholder: i18next.t('printer_selection.select_color'), toggleFlow: "horizontal", options: this.printerConfig.Color
285
+ h("ezp-select", { label: i18next.t('printer_selection.color'), icon: "color", placeholder: i18next.t('printer_selection.select_color'), toggleFlow: "horizontal", options: this.selectedPrinterConfig.Color
233
286
  ? [
234
287
  {
235
288
  id: 1,
@@ -252,27 +305,27 @@ export class EzpPrinterSelection {
252
305
  type: 'color',
253
306
  },
254
307
  ], preSelected: this.previouslySelectedProperties.color }),
255
- h("ezp-select", { label: i18next.t('printer_selection.orientation'), icon: "orientation", placeholder: i18next.t('printer_selection.select_orientation'), toggleFlow: "horizontal", options: this.printerConfig.OrientationsSupported.map((orientation, index) => ({
308
+ h("ezp-select", { label: i18next.t('printer_selection.orientation'), icon: "orientation", placeholder: i18next.t('printer_selection.select_orientation'), toggleFlow: "horizontal", options: this.selectedPrinterConfig.OrientationsSupported.map((orientation, index) => ({
256
309
  id: index,
257
310
  title: i18next.t(`printer_selection.orientation_${orientation}`),
258
311
  meta: '',
259
312
  type: 'orientation',
260
313
  })), preSelected: this.previouslySelectedProperties.orientation }),
261
- h("ezp-select", { label: i18next.t('printer_selection.size'), icon: "size", placeholder: i18next.t('printer_selection.select_size'), toggleFlow: "horizontal", optionFlow: "horizontal", options: this.printerConfig.PaperFormats.map((format) => ({
314
+ h("ezp-select", { label: i18next.t('printer_selection.size'), icon: "size", placeholder: i18next.t('printer_selection.select_size'), toggleFlow: "horizontal", optionFlow: "horizontal", options: this.selectedPrinterConfig.PaperFormats.map((format) => ({
262
315
  id: format.Id,
263
316
  title: format.Name,
264
317
  meta: `${format.XRes} x ${format.YRes}`,
265
318
  type: 'format',
266
319
  })), preSelected: this.previouslySelectedProperties.paper }),
267
- h("ezp-select", { label: i18next.t('printer_selection.quality'), icon: "quality", toggleFlow: "horizontal", options: this.printerConfig.Resolutions.map((option, index) => ({
320
+ h("ezp-select", { label: i18next.t('printer_selection.quality'), icon: "quality", toggleFlow: "horizontal", options: this.selectedPrinterConfig.Resolutions.map((option, index) => ({
268
321
  id: index,
269
322
  title: option,
270
323
  meta: '',
271
324
  type: 'quality',
272
325
  })), preSelected: !this.previouslySelectedProperties.resolution
273
- ? this.printerConfig.Resolutions[0]
326
+ ? this.selectedPrinterConfig.Resolutions[0]
274
327
  : this.previouslySelectedProperties.resolution }),
275
- this.printerConfig.DuplexSupported ? (h("ezp-select", { label: i18next.t('printer_selection.duplex'), icon: "duplex", toggleFlow: "horizontal", options: this.duplexOptions.map((option) => ({
328
+ this.selectedPrinterConfig.DuplexSupported ? (h("ezp-select", { label: i18next.t('printer_selection.duplex'), icon: "duplex", toggleFlow: "horizontal", options: this.duplexOptions.map((option) => ({
276
329
  id: option.id,
277
330
  title: option.title,
278
331
  meta: '',
@@ -379,6 +432,23 @@ export class EzpPrinterSelection {
379
432
  },
380
433
  "attribute": "filetype",
381
434
  "reflect": false
435
+ },
436
+ "fileid": {
437
+ "type": "string",
438
+ "mutable": false,
439
+ "complexType": {
440
+ "original": "string",
441
+ "resolved": "string",
442
+ "references": {}
443
+ },
444
+ "required": false,
445
+ "optional": false,
446
+ "docs": {
447
+ "tags": [],
448
+ "text": ""
449
+ },
450
+ "attribute": "fileid",
451
+ "reflect": false
382
452
  }
383
453
  }; }
384
454
  static get states() { return {
@@ -390,6 +460,7 @@ export class EzpPrinterSelection {
390
460
  "printers": {},
391
461
  "selectedPrinter": {},
392
462
  "printerConfig": {},
463
+ "selectedPrinterConfig": {},
393
464
  "selectedProperties": {},
394
465
  "previouslySelectedProperties": {}
395
466
  }; }
@@ -92,7 +92,7 @@ export class EzpPrinting {
92
92
  *
93
93
  */
94
94
  render() {
95
- return (h(Host, { class: `${userStore.state.theme} ${userStore.state.appearance}` }, this.authOpen ? (h("ezp-auth", { clientID: this.clientid, redirectURI: this.redirecturi, hidelogin: this.hidelogin })) : this.printOpen ? (h("ezp-printer-selection", { clientID: this.clientid, redirectURI: this.redirecturi, filename: this.filename, fileurl: this.fileurl, filetype: this.filetype })) : this.custom ? (h("slot", null)) : (h("ezp-icon-button", { id: "print-trigger", icon: "printer", slot: "trigger", type: "button", onClick: () => this.open() }))));
95
+ return (h(Host, { class: `${userStore.state.theme} ${userStore.state.appearance}` }, this.authOpen ? (h("ezp-auth", { clientID: this.clientid, redirectURI: this.redirecturi, hidelogin: this.hidelogin })) : this.printOpen ? (h("ezp-printer-selection", { clientID: this.clientid, redirectURI: this.redirecturi, filename: this.filename, fileurl: this.fileurl, filetype: this.filetype, fileid: this.fileid })) : this.custom ? (h("slot", null)) : (h("ezp-icon-button", { id: "print-trigger", icon: "printer", slot: "trigger", type: "button", onClick: () => this.open() }))));
96
96
  }
97
97
  static get is() { return "ezp-printing"; }
98
98
  static get encapsulation() { return "shadow"; }
@@ -279,6 +279,23 @@ export class EzpPrinting {
279
279
  "reflect": false,
280
280
  "defaultValue": "'cyan'"
281
281
  },
282
+ "fileid": {
283
+ "type": "string",
284
+ "mutable": false,
285
+ "complexType": {
286
+ "original": "string",
287
+ "resolved": "string",
288
+ "references": {}
289
+ },
290
+ "required": false,
291
+ "optional": false,
292
+ "docs": {
293
+ "tags": [],
294
+ "text": ""
295
+ },
296
+ "attribute": "fileid",
297
+ "reflect": false
298
+ },
282
299
  "appearance": {
283
300
  "type": "string",
284
301
  "mutable": false,
@@ -107,7 +107,17 @@ export class EzpPrintService {
107
107
  'Content-Type': 'application/json',
108
108
  },
109
109
  body: JSON.stringify(Object.assign(Object.assign(Object.assign({ fileurl: fileUrl, type: fileType, printerid: printerID }, (filename && { alias: filename })), (printAndDelete && { printanddelete: printAndDelete })), { properties })),
110
- }).then((response) => response.json());
110
+ });
111
+ }
112
+ printByFileID(accessToken, fileID, fileType, printerID, properties, filename, printAndDelete) {
113
+ return fetch(`https://${this.printingApi}/sfapi/Print/`, {
114
+ method: 'POST',
115
+ headers: {
116
+ Authorization: 'Bearer ' + accessToken,
117
+ 'Content-Type': 'application/json',
118
+ },
119
+ body: JSON.stringify(Object.assign(Object.assign(Object.assign({ fileid: fileID, type: fileType, printerid: printerID }, (filename && { alias: filename })), (printAndDelete && { printanddelete: printAndDelete })), { properties })),
120
+ });
111
121
  }
112
122
  }
113
123
  const printStore = createStore({
@@ -115,5 +125,11 @@ const printStore = createStore({
115
125
  jobID: '',
116
126
  printFinished: false,
117
127
  printApiHostUrl: '',
128
+ printerProperties: {},
129
+ fileID: '',
130
+ fileUrl: '',
131
+ fileType: '',
132
+ printerID: '',
133
+ fileName: ''
118
134
  });
119
135
  export default printStore;