@gisce/ooui 2.1.0 → 2.2.0

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gisce/ooui",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "engines": {
5
5
  "node": "20.5.0"
6
6
  },
package/src/Form.ts CHANGED
@@ -10,6 +10,7 @@ import { parseOnChange } from "./helpers/onChangeParser";
10
10
  import * as txml from "txml";
11
11
  import Field from "./Field";
12
12
  import Button from "./Button";
13
+ import Page from "./Page";
13
14
 
14
15
  export type FormParseOptions = {
15
16
  readOnly?: boolean;
@@ -233,6 +234,10 @@ class Form {
233
234
  key: `${this._keyIdx}`,
234
235
  };
235
236
 
237
+ if (container instanceof Page && container.readOnly) {
238
+ widgetProps.readonly = true;
239
+ }
240
+
236
241
  const widget = widgetFactory.createWidget(widgetType, widgetProps);
237
242
 
238
243
  if (widget.invisible && widget instanceof Field) {
@@ -3323,4 +3323,92 @@ describe("A Form", () => {
3323
3323
  const o2mField = form.findById("o2m") as One2many;
3324
3324
  expect(o2mField.height).toBe(50);
3325
3325
  });
3326
+ it("Should be able to parse a notebook tab with readonly attrs ", () => {
3327
+ const arch = `<?xml version="1.0"?>
3328
+ <form string="Partner Address">
3329
+ <notebook name="llibreta">
3330
+ <page string="General" attrs="{'readonly': [('state', '=', 'resum')]}">
3331
+ <field colspan="4" name="partner_id" select="1"/>
3332
+ </page>
3333
+ </notebook>
3334
+ </form>`;
3335
+ const form = new Form({
3336
+ ...FIELDS,
3337
+ state: {
3338
+ readonly: true,
3339
+ required: true,
3340
+ selection: [
3341
+ ["esborrany", "Borrador"],
3342
+ ["validar", "Validar"],
3343
+ ["pendent", "Pendiente"],
3344
+ ["activa", "Activa"],
3345
+ ["cancelada", "Cancelada"],
3346
+ ["contracte", "Activación Contrato"],
3347
+ ["novapolissa", "Creación nuevo contrato"],
3348
+ ["modcontractual", "Modificación Contractual"],
3349
+ ["impagament", "Impago"],
3350
+ ["tall", "Corte"],
3351
+ ["baixa", "Baja"],
3352
+ ["facturacio", "Facturación"],
3353
+ ],
3354
+ string: "Estado",
3355
+ type: "selection",
3356
+ views: {},
3357
+ },
3358
+ });
3359
+ form.parse(arch, {
3360
+ values: {
3361
+ state: "resum",
3362
+ },
3363
+ });
3364
+ const notebook = form.container.rows[0][0] as Notebook;
3365
+ expect(notebook).toBeInstanceOf(Notebook);
3366
+ const page = notebook.container.rows[0][0] as Page;
3367
+ expect(page).toBeInstanceOf(Page);
3368
+ expect(page.readOnly).toBeTruthy();
3369
+ });
3370
+ it("Should be able to parse a notebook tab with no readonly attrs ", () => {
3371
+ const arch = `<?xml version="1.0"?>
3372
+ <form string="Partner Address">
3373
+ <notebook name="llibreta">
3374
+ <page string="General" attrs="{'readonly': [('state', '=', 'resum')]}">
3375
+ <field colspan="4" name="partner_id" select="1"/>
3376
+ </page>
3377
+ </notebook>
3378
+ </form>`;
3379
+ const form = new Form({
3380
+ ...FIELDS,
3381
+ state: {
3382
+ readonly: true,
3383
+ required: true,
3384
+ selection: [
3385
+ ["esborrany", "Borrador"],
3386
+ ["validar", "Validar"],
3387
+ ["pendent", "Pendiente"],
3388
+ ["activa", "Activa"],
3389
+ ["cancelada", "Cancelada"],
3390
+ ["contracte", "Activación Contrato"],
3391
+ ["novapolissa", "Creación nuevo contrato"],
3392
+ ["modcontractual", "Modificación Contractual"],
3393
+ ["impagament", "Impago"],
3394
+ ["tall", "Corte"],
3395
+ ["baixa", "Baja"],
3396
+ ["facturacio", "Facturación"],
3397
+ ],
3398
+ string: "Estado",
3399
+ type: "selection",
3400
+ views: {},
3401
+ },
3402
+ });
3403
+ form.parse(arch, {
3404
+ values: {
3405
+ state: "baixa",
3406
+ },
3407
+ });
3408
+ const notebook = form.container.rows[0][0] as Notebook;
3409
+ expect(notebook).toBeInstanceOf(Notebook);
3410
+ const page = notebook.container.rows[0][0] as Page;
3411
+ expect(page).toBeInstanceOf(Page);
3412
+ expect(page.readOnly).toBeFalsy();
3413
+ });
3326
3414
  });