jamespot-front-business 1.1.68 → 1.1.70

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/dist/esm.js CHANGED
@@ -231,7 +231,7 @@ const animationStatsSlice = createSlice({
231
231
  builder.addCase(fetchAnimationStats.rejected, (state) => {
232
232
  state.loading = 'idle';
233
233
  });
234
- }
234
+ },
235
235
  });
236
236
 
237
237
  const fetchAnimationStatsCurrent = createAsyncThunk('animations/fetchAnimationStatsCurrent', (uri, { extra, rejectWithValue, dispatch }) => __awaiter(void 0, void 0, void 0, function* () {
@@ -263,7 +263,7 @@ const animationStatsCurrentSlice = createSlice({
263
263
  builder.addCase(fetchAnimationStatsCurrent.rejected, (state) => {
264
264
  state.loading = 'idle';
265
265
  });
266
- }
266
+ },
267
267
  });
268
268
 
269
269
  const selectCurrentAnimation = (state) => state.animations.animationsList.animationConfiguration;
@@ -2073,7 +2073,7 @@ const TinyMCEOptionsSlice = createSlice({
2073
2073
  initialState: initialState$5,
2074
2074
  reducers: {
2075
2075
  initOptions: (_, { payload }) => {
2076
- return { common: payload };
2076
+ return payload;
2077
2077
  },
2078
2078
  },
2079
2079
  });
@@ -2088,11 +2088,15 @@ const TinyMCESlice = {
2088
2088
  const selectTinyMCECommonOptions = (state) => {
2089
2089
  return state.tinymce.options.common;
2090
2090
  };
2091
+ const selectTinyMCEExtendedOptions = (state) => {
2092
+ return state.tinymce.options.extended;
2093
+ };
2091
2094
  const TinyMCE = {
2092
2095
  slice: TinyMCESlice,
2093
2096
  actions: Object.assign({}, TinyMCEOptionsSlice.actions),
2094
2097
  selectors: {
2095
2098
  selectTinyMCECommonOptions,
2099
+ selectTinyMCEExtendedOptions,
2096
2100
  },
2097
2101
  };
2098
2102
 
@@ -2442,28 +2446,6 @@ function content(name) {
2442
2446
  }
2443
2447
  }
2444
2448
 
2445
- const getWidgetRTHandlers = function (dispatch, uniqid) {
2446
- const widgetPresenceResponseHandler = function (message) {
2447
- if (message.namespace === 'WIDGET' && message.function === 'widget-presence-response') {
2448
- if (message.data && message.data.uniqid === uniqid) {
2449
- dispatch(Widget.slice.actions.registerWidgetRTObject({
2450
- uniqid: message.data.uniqid,
2451
- object: message.data.object,
2452
- }));
2453
- }
2454
- }
2455
- };
2456
- return [
2457
- {
2458
- namespace: 'WIDGET',
2459
- function: 'widget-presence-response',
2460
- handler: widgetPresenceResponseHandler,
2461
- },
2462
- ];
2463
- };
2464
-
2465
- const MODE_EDIT = 'edit';
2466
- const MODE_VIEW = 'view';
2467
2449
  const initialState$3 = {
2468
2450
  token: undefined,
2469
2451
  ids: {},
@@ -2633,6 +2615,27 @@ const widgetsSlice = createSlice({
2633
2615
  },
2634
2616
  },
2635
2617
  });
2618
+
2619
+ const getWidgetRTHandlers = function (dispatch, uniqid) {
2620
+ const widgetPresenceResponseHandler = function (message) {
2621
+ if (message.namespace === 'WIDGET' && message.function === 'widget-presence-response') {
2622
+ if (message.data && message.data.uniqid === uniqid) {
2623
+ dispatch(widgetsSlice.actions.registerWidgetRTObject({
2624
+ uniqid: message.data.uniqid,
2625
+ object: message.data.object,
2626
+ }));
2627
+ }
2628
+ }
2629
+ };
2630
+ return [
2631
+ {
2632
+ namespace: 'WIDGET',
2633
+ function: 'widget-presence-response',
2634
+ handler: widgetPresenceResponseHandler,
2635
+ },
2636
+ ];
2637
+ };
2638
+
2636
2639
  const selectToken = (state) => state.widgets.token;
2637
2640
  const selectModal = (state) => state.widgets.modal;
2638
2641
  const selectWidgets = (state) => state.widgets.ids;
@@ -2757,12 +2760,11 @@ const AUDIENCE = {
2757
2760
  ALL: '1',
2758
2761
  CUSTOM: '0',
2759
2762
  };
2760
- var StatusType$1;
2761
- (function (StatusType) {
2762
- StatusType["draft"] = "draft";
2763
- StatusType["installed"] = "installed";
2764
- StatusType["suspended"] = "suspended";
2765
- })(StatusType$1 || (StatusType$1 = {}));
2763
+ const StatusType$1 = {
2764
+ draft: 'draft',
2765
+ installed: 'installed',
2766
+ suspended: 'suspended',
2767
+ };
2766
2768
  const APP_STATUS_TYPE = {
2767
2769
  DRAFT: StatusType$1.draft,
2768
2770
  INSTALLED: StatusType$1.installed,
@@ -2773,51 +2775,50 @@ const STUDIO_VIEW = {
2773
2775
  NOT_SOLR: '0',
2774
2776
  };
2775
2777
  const viewsList = ['create', 'popup', 'edit', 'filter', 'list', 'view'];
2776
- var AppFormItemTypes;
2777
- (function (AppFormItemTypes) {
2778
- AppFormItemTypes["IMAGE"] = "IMAGE";
2779
- AppFormItemTypes["DESCRIPTION"] = "DESCRIPTION";
2780
- AppFormItemTypes["TEXT"] = "TEXT";
2781
- AppFormItemTypes["TEXTAREA"] = "TEXTAREA";
2782
- AppFormItemTypes["TEXTAREAHTML"] = "TEXTAREAHTML";
2783
- AppFormItemTypes["DATE"] = "DATE";
2784
- AppFormItemTypes["DATETIME"] = "DATETIME";
2785
- AppFormItemTypes["NUMBER"] = "NUMBER";
2786
- AppFormItemTypes["URL"] = "URL";
2787
- AppFormItemTypes["EMAIL"] = "EMAIL";
2788
- AppFormItemTypes["SELECT"] = "SELECT";
2789
- AppFormItemTypes["CHECKBOX"] = "CHECKBOX";
2790
- AppFormItemTypes["TOGGLE"] = "TOGGLE";
2791
- AppFormItemTypes["RADIO"] = "RADIO";
2792
- AppFormItemTypes["TAGS"] = "TAGS";
2793
- AppFormItemTypes["ADDFILEATTACHMENT"] = "ADDFILEATTACHMENT";
2794
- AppFormItemTypes["CODEHTML"] = "CODEHTML";
2795
- AppFormItemTypes["USERLINK"] = "USERLINK";
2796
- AppFormItemTypes["CONTENTLINK"] = "CONTENTLINK";
2797
- AppFormItemTypes["RANGE"] = "RANGE";
2798
- })(AppFormItemTypes || (AppFormItemTypes = {}));
2799
- var ExtraAppFieldsItemViews;
2800
- (function (ExtraAppFieldsItemViews) {
2801
- ExtraAppFieldsItemViews["TITLE"] = "TITLE";
2802
- ExtraAppFieldsItemViews["USER"] = "USER";
2803
- ExtraAppFieldsItemViews["PUBLISHTO"] = "PUBLISHTO";
2804
- ExtraAppFieldsItemViews["SENDALERTTOSUBSCRIBERS"] = "SENDALERTTOSUBSCRIBERS";
2805
- ExtraAppFieldsItemViews["RECEIVEACOPY"] = "RECEIVEACOPY";
2806
- ExtraAppFieldsItemViews["CREATIONDATE"] = "CREATIONDATE";
2807
- })(ExtraAppFieldsItemViews || (ExtraAppFieldsItemViews = {}));
2808
- var AppFieldFormPropertyTypes;
2809
- (function (AppFieldFormPropertyTypes) {
2810
- AppFieldFormPropertyTypes["LABEL"] = "label";
2811
- AppFieldFormPropertyTypes["DESCRIPTION"] = "description";
2812
- AppFieldFormPropertyTypes["RICHTEXT"] = "richtext";
2813
- AppFieldFormPropertyTypes["CHECKBOX"] = "checkbox";
2814
- AppFieldFormPropertyTypes["OPTIONS_EDITOR"] = "options_editor";
2815
- AppFieldFormPropertyTypes["TAXONOMY"] = "taxonomy";
2816
- AppFieldFormPropertyTypes["CONTENTTYPE"] = "contenttype";
2817
- })(AppFieldFormPropertyTypes || (AppFieldFormPropertyTypes = {}));
2778
+ const AppFormItemTypes = {
2779
+ IMAGE: 'IMAGE',
2780
+ DESCRIPTION: 'DESCRIPTION',
2781
+ TEXT: 'TEXT',
2782
+ TEXTAREA: 'TEXTAREA',
2783
+ TEXTAREAHTML: 'TEXTAREAHTML',
2784
+ DATE: 'DATE',
2785
+ DATETIME: 'DATETIME',
2786
+ NUMBER: 'NUMBER',
2787
+ URL: 'URL',
2788
+ EMAIL: 'EMAIL',
2789
+ SELECT: 'SELECT',
2790
+ CHECKBOX: 'CHECKBOX',
2791
+ TOGGLE: 'TOGGLE',
2792
+ RADIO: 'RADIO',
2793
+ TAGS: 'TAGS',
2794
+ ADDFILEATTACHMENT: 'ADDFILEATTACHMENT',
2795
+ CODEHTML: 'CODEHTML',
2796
+ USERLINK: 'USERLINK',
2797
+ CONTENTLINK: 'CONTENTLINK',
2798
+ RANGE: 'RANGE',
2799
+ };
2800
+ const ExtraAppFieldsItemViews = {
2801
+ TITLE: 'TITLE',
2802
+ USER: 'USER',
2803
+ PUBLISHTO: 'PUBLISHTO',
2804
+ SENDALERTTOSUBSCRIBERS: 'SENDALERTTOSUBSCRIBERS',
2805
+ RECEIVEACOPY: 'RECEIVEACOPY',
2806
+ CREATIONDATE: 'CREATIONDATE',
2807
+ };
2808
+ const AppFieldFormPropertyTypes = {
2809
+ LABEL: 'label',
2810
+ DESCRIPTION: 'description',
2811
+ RICHTEXT: 'richtext',
2812
+ CHECKBOX: 'checkbox',
2813
+ OPTIONS_EDITOR: 'options_editor',
2814
+ TAXONOMY: 'taxonomy',
2815
+ CONTENTTYPE: 'contenttype',
2816
+ };
2818
2817
  const AppFormUniqueList = [AppFormItemTypes.DESCRIPTION, AppFormItemTypes.IMAGE];
2818
+ const AppFormUniqueListCheck = AppFormUniqueList;
2819
2819
  const AppFormBannedFromViews$1 = new Map();
2820
2820
  AppFormBannedFromViews$1.set(AppFormItemTypes.IMAGE, ['list', 'filter', 'view']);
2821
+ AppFormBannedFromViews$1.set(AppFormItemTypes.CODEHTML, ['list', 'filter', 'view']);
2821
2822
  const MapExtraFieldsWithView = {
2822
2823
  create: {
2823
2824
  fixed: [ExtraAppFieldsItemViews.TITLE],
@@ -2855,6 +2856,7 @@ const AppColumnsDefaultTypes = [
2855
2856
  AppFormItemTypes.DESCRIPTION,
2856
2857
  ];
2857
2858
  const AppFormPrimaryList = [AppFormItemTypes.DESCRIPTION];
2859
+ const AppFormPrimaryListValues = AppFormPrimaryList;
2858
2860
  const AppFormFixedList$1 = [
2859
2861
  ExtraAppFieldsItemViews.TITLE,
2860
2862
  ExtraAppFieldsItemViews.PUBLISHTO,
@@ -2869,6 +2871,18 @@ const AppFormNoAsFieldList = [
2869
2871
  ];
2870
2872
  const AppFormFieldOnlyInView = [AppFormItemTypes.CODEHTML];
2871
2873
  const AppFormNonPrimaryList = AppFormNoAsFieldList.concat(AppFormFieldOnlyInView).concat(AppFormPrimaryList);
2874
+ var Element;
2875
+ (function (Element) {
2876
+ Element["Attr"] = "attr";
2877
+ Element["PublishTo"] = "publishTo";
2878
+ })(Element || (Element = {}));
2879
+ var Description;
2880
+ (function (Description) {
2881
+ Description["Empty"] = "";
2882
+ Description["FieldTagDescription"] = "Field_Tag_Description";
2883
+ Description["FieldTitleDescription"] = "Field_Title_Description";
2884
+ Description["WWWDescCOM"] = "www.desc.com";
2885
+ })(Description || (Description = {}));
2872
2886
 
2873
2887
  var StatusType;
2874
2888
  (function (StatusType) {
@@ -3132,23 +3146,761 @@ function migrateJson(v1Json) {
3132
3146
  return v2;
3133
3147
  }
3134
3148
 
3135
- function InstalledAppStudioAdapter(serverApp, serverApps) {
3149
+ function generateNewFormField(type, viewsDefault = true) {
3150
+ return {
3151
+ id: v4(),
3152
+ type,
3153
+ properties: _setFieldProperties(type),
3154
+ mandatory: false,
3155
+ views: {
3156
+ create: viewsDefault,
3157
+ popup: viewsDefault,
3158
+ edit: viewsDefault,
3159
+ list: viewsDefault,
3160
+ filter: viewsDefault,
3161
+ view: viewsDefault,
3162
+ },
3163
+ isActive: true,
3164
+ isFixed: false,
3165
+ isOptional: false,
3166
+ value: null,
3167
+ isLockedValue: false,
3168
+ };
3169
+ }
3170
+ const taxonomyDefaultValue = {
3171
+ type: 'taxonomyOpen',
3172
+ id: 1,
3173
+ title: 'Mots-clés',
3174
+ };
3175
+ const contentTypeDefaultValue = {
3176
+ type: 'mpArticle',
3177
+ label: 'Article',
3178
+ };
3179
+ function _setFieldProperties(type) {
3180
+ switch (type) {
3181
+ case AppFormItemTypes.TEXT:
3182
+ case AppFormItemTypes.DESCRIPTION:
3183
+ case AppFormItemTypes.TEXTAREAHTML:
3184
+ case AppFormItemTypes.DATE:
3185
+ case AppFormItemTypes.DATETIME:
3186
+ case AppFormItemTypes.URL:
3187
+ case AppFormItemTypes.EMAIL:
3188
+ case AppFormItemTypes.TOGGLE:
3189
+ case AppFormItemTypes.USERLINK:
3190
+ return [
3191
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3192
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3193
+ ];
3194
+ case AppFormItemTypes.ADDFILEATTACHMENT:
3195
+ return [{ propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' }];
3196
+ case AppFormItemTypes.CODEHTML:
3197
+ return [{ propertyType: AppFieldFormPropertyTypes.RICHTEXT, value: '' }];
3198
+ case AppFormItemTypes.TEXTAREA:
3199
+ return [
3200
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3201
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3202
+ ];
3203
+ case AppFormItemTypes.NUMBER:
3204
+ return [
3205
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3206
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3207
+ {
3208
+ propertyType: AppFieldFormPropertyTypes.CHECKBOX,
3209
+ value: false,
3210
+ checkBoxOptions: [{ label: 'APPSTUDIO_FormEditProps_Digits', value: false }],
3211
+ },
3212
+ ];
3213
+ case AppFormItemTypes.SELECT:
3214
+ return [
3215
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3216
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3217
+ {
3218
+ propertyType: AppFieldFormPropertyTypes.OPTIONS_EDITOR,
3219
+ value: [],
3220
+ isOptionsEditorEnhanced: true,
3221
+ },
3222
+ ];
3223
+ case AppFormItemTypes.CHECKBOX:
3224
+ case AppFormItemTypes.RADIO:
3225
+ return [
3226
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3227
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3228
+ {
3229
+ propertyType: AppFieldFormPropertyTypes.OPTIONS_EDITOR,
3230
+ value: [],
3231
+ },
3232
+ ];
3233
+ case AppFormItemTypes.TAGS:
3234
+ return [
3235
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3236
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3237
+ {
3238
+ propertyType: AppFieldFormPropertyTypes.TAXONOMY,
3239
+ value: Object.assign({}, taxonomyDefaultValue),
3240
+ },
3241
+ ];
3242
+ case AppFormItemTypes.CONTENTLINK:
3243
+ return [
3244
+ { propertyType: AppFieldFormPropertyTypes.LABEL, isRequired: true, value: '' },
3245
+ { propertyType: AppFieldFormPropertyTypes.DESCRIPTION, value: '' },
3246
+ {
3247
+ propertyType: AppFieldFormPropertyTypes.CONTENTTYPE,
3248
+ value: Object.assign({}, contentTypeDefaultValue),
3249
+ },
3250
+ ];
3251
+ default:
3252
+ return [];
3253
+ }
3254
+ }
3255
+
3256
+ function _initField(type, installedField) {
3257
+ const field = Object.assign(Object.assign({}, generateNewFormField(type, false)), { id: installedField.name, mandatory: installedField.mandatory });
3258
+ field.properties[0].value = installedField.label;
3259
+ field.properties[1].value = installedField.description;
3260
+ return field;
3261
+ }
3262
+ function _getOptions(installedOptions) {
3263
+ const options = [];
3264
+ Object.keys(installedOptions).forEach((optionKey) => {
3265
+ options.push({
3266
+ title: installedOptions[optionKey],
3267
+ value: optionKey,
3268
+ });
3269
+ });
3270
+ return options;
3271
+ }
3272
+ function createAddfileattachmentField(installedField) {
3273
+ const field = Object.assign(Object.assign({}, generateNewFormField(AppFormItemTypes.ADDFILEATTACHMENT, false)), { id: installedField.name, mandatory: installedField.mandatory });
3274
+ field.properties[0].value = installedField.label;
3275
+ return field;
3276
+ }
3277
+ function createHtmlField(formItem) {
3278
+ const field = Object.assign(Object.assign({}, generateNewFormField(AppFormItemTypes.CODEHTML, false)), { id: formItem.name });
3279
+ field.properties[0].value = formItem.properties.code;
3280
+ return field;
3281
+ }
3282
+ function createImageField() {
3283
+ const field = generateNewFormField(AppFormItemTypes.IMAGE, false);
3284
+ return field;
3285
+ }
3286
+ function createNumberField(installedField) {
3287
+ var _a;
3288
+ const field = _initField(AppFormItemTypes.NUMBER, installedField);
3289
+ field.properties[2].value = ((_a = installedField.widget.params) === null || _a === void 0 ? void 0 : _a.step) === '0.01';
3290
+ return field;
3291
+ }
3292
+ function createTagsField(installedField) {
3293
+ var _a, _b;
3294
+ const field = _initField(AppFormItemTypes.TAGS, installedField);
3295
+ field.properties[2].value.id = +((_b = (_a = installedField.widget.params) === null || _a === void 0 ? void 0 : _a.idTaxonomy) !== null && _b !== void 0 ? _b : 1);
3296
+ return field;
3297
+ }
3298
+ function createSelectField(installedField) {
3299
+ var _a, _b, _c, _d, _e;
3300
+ const field = _initField(AppFormItemTypes.SELECT, installedField);
3301
+ const defaultValue = ((_a = installedField.widget.params) === null || _a === void 0 ? void 0 : _a.defaultValue)
3302
+ ? {
3303
+ title: installedField.widget.options[(_b = installedField.widget.params) === null || _b === void 0 ? void 0 : _b.defaultValue],
3304
+ value: (_c = installedField.widget.params) === null || _c === void 0 ? void 0 : _c.defaultValue,
3305
+ }
3306
+ : undefined;
3307
+ const optionsEditorValue = {
3308
+ propertyOptions: _getOptions(installedField.widget.options),
3309
+ canSelectMultiple: installedField.widget.multiple === '1',
3310
+ userCanModifiyByComment: ((_d = installedField.widget.params) === null || _d === void 0 ? void 0 : _d.explain) === '1',
3311
+ defaultSelectOption: !!((_e = installedField.widget.params) === null || _e === void 0 ? void 0 : _e.defaultValue),
3312
+ defaultSelectOptionValue: defaultValue,
3313
+ };
3314
+ field.properties[2].value = optionsEditorValue;
3315
+ return field;
3316
+ }
3317
+ function createRadioField(installedField) {
3318
+ const field = _initField(AppFormItemTypes.RADIO, installedField);
3319
+ const optionsEditorValue = {
3320
+ propertyOptions: _getOptions(installedField.widget.options),
3321
+ };
3322
+ field.properties[2].value = optionsEditorValue;
3323
+ return field;
3324
+ }
3325
+ function createCheckboxField(installedField) {
3326
+ const field = createRadioField(installedField);
3327
+ field.type = AppFormItemTypes.CHECKBOX;
3328
+ return field;
3329
+ }
3330
+ function createContentLinkField(installedField, state) {
3331
+ var _a, _b;
3332
+ const field = _initField(AppFormItemTypes.CONTENTLINK, installedField);
3333
+ field.properties[2].value.type = (_a = installedField.widget.params.types) !== null && _a !== void 0 ? _a : 'mpArticle';
3334
+ const modelState = state.entities === undefined ? undefined : { entities: state.entities };
3335
+ const model = modelState ? Model.selectors.selectById(modelState, field.properties[2].value.type) : undefined;
3336
+ field.properties[2].value.label = (_b = model === null || model === void 0 ? void 0 : model.label) !== null && _b !== void 0 ? _b : 'Article';
3337
+ return field;
3338
+ }
3339
+ function createTextField(installedField) {
3340
+ const field = _initField(AppFormItemTypes.TEXT, installedField);
3341
+ return field;
3342
+ }
3343
+ function createDescriptionField(installedField) {
3344
+ const field = _initField(AppFormItemTypes.DESCRIPTION, installedField);
3345
+ return field;
3346
+ }
3347
+ function createTextareaHTMLField(installedField) {
3348
+ const field = _initField(AppFormItemTypes.TEXTAREAHTML, installedField);
3349
+ return field;
3350
+ }
3351
+ function createDateField(installedField) {
3352
+ const field = _initField(AppFormItemTypes.DATE, installedField);
3353
+ return field;
3354
+ }
3355
+ function createDatetimeField(installedField) {
3356
+ const field = _initField(AppFormItemTypes.DATETIME, installedField);
3357
+ return field;
3358
+ }
3359
+ function createUrlField(installedField) {
3360
+ const field = _initField(AppFormItemTypes.URL, installedField);
3361
+ return field;
3362
+ }
3363
+ function createEmailField(installedField) {
3364
+ const field = _initField(AppFormItemTypes.EMAIL, installedField);
3365
+ return field;
3366
+ }
3367
+ function createToggleField(installedField) {
3368
+ const field = _initField(AppFormItemTypes.TOGGLE, installedField);
3369
+ return field;
3370
+ }
3371
+ function createUserLinkField(installedField) {
3372
+ const field = _initField(AppFormItemTypes.USERLINK, installedField);
3373
+ return field;
3374
+ }
3375
+ function createTextAreaField(installedField) {
3376
+ const field = _initField(AppFormItemTypes.TEXTAREA, installedField);
3377
+ return field;
3378
+ }
3379
+
3380
+ const installedToV2ViewNames = {
3381
+ 'create-popup': 'popup',
3382
+ create: 'create',
3383
+ edit: 'edit',
3384
+ display: 'view',
3385
+ };
3386
+ const specialAttrName = ['title', 'alertAuthor', 'sendAlert'];
3387
+ const ignoredFields = ['edito'];
3388
+ function updateViewsFromFields(clonedApp, appFields) {
3389
+ return Object.assign({}, ...viewsList.map((view) => {
3390
+ const viewItems = {};
3391
+ Object.entries(clonedApp.views[view]).forEach(([fieldId, field]) => {
3392
+ if (field.isFixed) {
3393
+ viewItems[fieldId] = field;
3394
+ }
3395
+ if (field.isOptional) {
3396
+ viewItems[fieldId] = field;
3397
+ }
3398
+ });
3399
+ appFields.forEach((field, idx) => {
3400
+ var _a, _b, _c, _d, _e, _f, _g, _h;
3401
+ const isFieldUsedInView = field.views[view];
3402
+ const isExistingField = Object.keys(clonedApp.views[view]).includes(field.id);
3403
+ const fieldType = field.type;
3404
+ if (AppFormBannedFromViews$1.get(fieldType) && ((_a = AppFormBannedFromViews$1.get(fieldType)) === null || _a === void 0 ? void 0 : _a.includes(view))) {
3405
+ return;
3406
+ }
3407
+ let fieldValue = undefined;
3408
+ if (fieldType === AppFormItemTypes.CODEHTML) {
3409
+ const richTextProperty = (_b = field.properties) === null || _b === void 0 ? void 0 : _b.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.RICHTEXT);
3410
+ if (richTextProperty === null || richTextProperty === void 0 ? void 0 : richTextProperty.value) {
3411
+ fieldValue = richTextProperty === null || richTextProperty === void 0 ? void 0 : richTextProperty.value;
3412
+ }
3413
+ }
3414
+ if (fieldType === AppFormItemTypes.SELECT) {
3415
+ const selectProperty = (_c = field.properties) === null || _c === void 0 ? void 0 : _c.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3416
+ if (isExistingField) {
3417
+ const exField = clonedApp.views[view][field.id];
3418
+ const exSelectProperty = (_d = exField.properties) === null || _d === void 0 ? void 0 : _d.find((prop) => prop.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR);
3419
+ const isMultivalued = !!((_e = selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value) === null || _e === void 0 ? void 0 : _e.canSelectMultiple);
3420
+ const exIsMultivalued = !!((_f = exSelectProperty === null || exSelectProperty === void 0 ? void 0 : exSelectProperty.value) === null || _f === void 0 ? void 0 : _f.canSelectMultiple);
3421
+ if (isMultivalued === exIsMultivalued) {
3422
+ fieldValue = exField.value;
3423
+ }
3424
+ }
3425
+ else {
3426
+ const isEnhancedSelect = !!(selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.isOptionsEditorEnhanced);
3427
+ const defaultValue = isEnhancedSelect && !!(selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value.defaultSelectOption)
3428
+ ? selectProperty === null || selectProperty === void 0 ? void 0 : selectProperty.value.defaultSelectOptionValue
3429
+ : '';
3430
+ if (defaultValue) {
3431
+ fieldValue = defaultValue;
3432
+ }
3433
+ }
3434
+ }
3435
+ if (isExistingField) {
3436
+ const exField = clonedApp.views[view][field.id];
3437
+ viewItems[field.id] = Object.assign(Object.assign(Object.assign(Object.assign({}, exField), { properties: field.properties || exField.properties || [] }), (fieldValue !== undefined && { value: fieldValue })), { isUsed: isFieldUsedInView, pos: ((_g = clonedApp.syncViewFieldOrder) === null || _g === void 0 ? void 0 : _g[view]) ? idx : exField.pos, isLockedValue: (fieldValue !== undefined || exField.value !== undefined) && exField.isLockedValue });
3438
+ }
3439
+ else {
3440
+ const existingFieldsLen = Object.values(clonedApp.views[view]).filter((v) => !v.isFixed && !v.isOptional).length;
3441
+ viewItems[field.id] = {
3442
+ type: field.type,
3443
+ properties: field.properties || [],
3444
+ isUsed: isFieldUsedInView,
3445
+ isOptional: false,
3446
+ isLockedValue: false,
3447
+ isFixed: false,
3448
+ value: fieldValue !== null && fieldValue !== void 0 ? fieldValue : null,
3449
+ pos: ((_h = clonedApp.syncViewFieldOrder) === null || _h === void 0 ? void 0 : _h[view]) ? idx : existingFieldsLen + idx,
3450
+ };
3451
+ }
3452
+ });
3453
+ return {
3454
+ [view]: viewItems,
3455
+ };
3456
+ }));
3457
+ }
3458
+ function buildAudience(accessRightObjectList) {
3459
+ return accessRightObjectList.map((accessRightObject) => {
3460
+ return {
3461
+ id: `${accessRightObject.type}/${accessRightObject.id}`,
3462
+ uri: `${accessRightObject.type}/${accessRightObject.id}`,
3463
+ shortUri: `${accessRightObject.type}/${accessRightObject.id}`,
3464
+ title: accessRightObject.title,
3465
+ name: accessRightObject.title,
3466
+ mainType: accessRightObject.type,
3467
+ type: accessRightObject.mainType,
3468
+ label: accessRightObject.type,
3469
+ cssClass: accessRightObject._cssClass,
3470
+ cssColor: accessRightObject._cssColor,
3471
+ class: accessRightObject._cssClass,
3472
+ Pseudo: accessRightObject.title,
3473
+ _url: accessRightObject._url,
3474
+ };
3475
+ });
3476
+ }
3477
+ function populateFieldsAndViews(app, appS, state) {
3478
+ const tables = app.typeModel.tables;
3479
+ const displays = app.typeModel.displays;
3480
+ if (!displays) {
3481
+ return;
3482
+ }
3483
+ const registeredFields = new Map();
3484
+ Object.entries(displays).forEach((displaysEntry) => {
3485
+ const [displayName, displayValue] = displaysEntry;
3486
+ if (Object.keys(installedToV2ViewNames).includes(displayName)) {
3487
+ buildView(appS, registeredFields, displayName, displayValue, tables, state);
3488
+ }
3489
+ });
3490
+ buildListView(appS, registeredFields, app.columns, tables, state);
3491
+ buildFilterView(appS, registeredFields, app.attrExposed, tables, state);
3492
+ }
3493
+ function buildView(appS, registeredFields, displayName, displayValue, tables, state) {
3494
+ const newName = installedToV2ViewNames[displayName];
3495
+ appS.views[newName] = {};
3496
+ displayValue.composants.forEach((viewComponent, index) => {
3497
+ let field = undefined;
3498
+ if (viewComponent.name && ignoredFields.includes(viewComponent.name)) {
3499
+ return;
3500
+ }
3501
+ const [fieldIdx, fixedInfo] = createOrGetField(appS, registeredFields, viewComponent, tables, state);
3502
+ if (fieldIdx === -1 && fixedInfo) {
3503
+ switch (fixedInfo.ref) {
3504
+ case 'title':
3505
+ addTitleToView(newName, appS, fixedInfo);
3506
+ break;
3507
+ case 'alertAuthor':
3508
+ addAlertAuthorToView(newName, appS, fixedInfo);
3509
+ break;
3510
+ case 'sendAlert':
3511
+ addSendAlertToView(newName, appS, fixedInfo);
3512
+ break;
3513
+ case 'publishTo':
3514
+ addPublishToToView(newName, appS, fixedInfo);
3515
+ break;
3516
+ default:
3517
+ console.error('fixed field info with unsupported ref ', fixedInfo);
3518
+ break;
3519
+ }
3520
+ }
3521
+ else if (fieldIdx !== -1) {
3522
+ field = appS.fields[fieldIdx];
3523
+ if (!field || !field.views) {
3524
+ throw new Error(`error converting installed app to V2: created field not found in fields array: ${fieldIdx}, ${fixedInfo}`);
3525
+ }
3526
+ field.views[newName] = true;
3527
+ addFieldToView(newName, field, appS, index, fixedInfo);
3528
+ }
3529
+ });
3530
+ }
3531
+ function buildListView(appS, registeredFields, columns, tables, state) {
3532
+ if (!columns) {
3533
+ return;
3534
+ }
3535
+ Object.keys(columns).forEach((fieldRef, index) => {
3536
+ addFieldToViewFromRef(appS, registeredFields, tables, 'list', fieldRef, index, state);
3537
+ });
3538
+ }
3539
+ function buildFilterView(appS, registeredFields, attrExposed, tables, state) {
3540
+ attrExposed.forEach((fieldRef, index) => {
3541
+ addFieldToViewFromRef(appS, registeredFields, tables, 'filter', fieldRef, index, state);
3542
+ });
3543
+ }
3544
+ function addFieldToViewFromRef(appS, registeredFields, tables, viewName, fieldRef, index, state) {
3545
+ switch (fieldRef) {
3546
+ case 'title':
3547
+ addTitleToView(viewName, appS, { ref: 'title', fixedValue: undefined });
3548
+ break;
3549
+ case 'iduser':
3550
+ case 'idUser':
3551
+ addUserToView(viewName, appS);
3552
+ break;
3553
+ case 'datecreation':
3554
+ case 'dateCreation':
3555
+ addDateCreationToView(viewName, appS);
3556
+ break;
3557
+ default:
3558
+ defaultFieldCreation(appS, registeredFields, tables, viewName, fieldRef, index, state);
3559
+ break;
3560
+ }
3561
+ }
3562
+ function defaultFieldCreation(appS, registeredFields, tables, viewName, fieldRef, index, state) {
3563
+ const fieldIndex = createOrGetFieldFromRef(appS, registeredFields, tables, fieldRef, state);
3564
+ const field = appS.fields[fieldIndex];
3565
+ if (!field || !field.views) {
3566
+ throw new Error(`error converting installed app to V2: unable to handle ${fieldRef} in list view`);
3567
+ }
3568
+ field.views[viewName] = true;
3569
+ addFieldToView(viewName, field, appS, index, undefined);
3570
+ }
3571
+ function createOrGetFieldFromRef(appS, registeredFields, tables, fieldRef, state) {
3572
+ const knownIndex = registeredFields.get(fieldRef);
3573
+ if (knownIndex !== undefined) {
3574
+ return knownIndex;
3575
+ }
3576
+ const [ref, indexCreated] = createStudioDefinedField(appS, fieldRef, tables, state);
3577
+ registeredFields.set(ref, indexCreated);
3578
+ return indexCreated;
3579
+ }
3580
+ function createOrGetField(appS, registeredFields, viewComponent, tables, state) {
3581
+ if (viewComponent.name !== undefined && viewComponent.element === 'attr') {
3582
+ if (specialAttrName.includes(viewComponent.name)) {
3583
+ return [-1, { ref: viewComponent.name, fixedValue: undefined }];
3584
+ }
3585
+ const knownIndex = registeredFields.get(viewComponent.name);
3586
+ if (knownIndex !== undefined) {
3587
+ return [knownIndex, undefined];
3588
+ }
3589
+ const [ref, indexCreated] = createStudioDefinedField(appS, viewComponent.name, tables, state);
3590
+ registeredFields.set(ref, indexCreated);
3591
+ return [indexCreated, undefined];
3592
+ }
3593
+ else if (viewComponent.element === 'html') {
3594
+ const htmlCode = viewComponent.html;
3595
+ if (htmlCode === undefined) {
3596
+ console.error('error while parsing studio installed html attr in a view: no html code');
3597
+ return [-1, undefined];
3598
+ }
3599
+ if (htmlCode.includes('<JAMESPOT.STUDIO.FIXED>')) {
3600
+ const startPos = htmlCode.indexOf('<JAMESPOT.STUDIO.FIXED>') + '<JAMESPOT.STUDIO.FIXED>'.length;
3601
+ const endPos = htmlCode.indexOf('</JAMESPOT.STUDIO.FIXED>');
3602
+ const formItemRefString = htmlCode.substring(startPos, endPos);
3603
+ try {
3604
+ const formItemRef = JSON.parse(formItemRefString);
3605
+ if ((formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref.toUpperCase()) in ExtraAppFieldsItemViews ||
3606
+ specialAttrName.includes(formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref)) {
3607
+ return [-1, formItemRef];
3608
+ }
3609
+ const knownIndex = registeredFields.get(formItemRef === null || formItemRef === void 0 ? void 0 : formItemRef.ref);
3610
+ if (knownIndex !== undefined) {
3611
+ return [knownIndex, formItemRef];
3612
+ }
3613
+ const [ref, indexCreated] = createStudioDefinedField(appS, formItemRef.ref, tables, state);
3614
+ registeredFields.set(ref, indexCreated);
3615
+ return [indexCreated, formItemRef];
3616
+ }
3617
+ catch (_) {
3618
+ console.error('error while parsing studio installed fixed attr in a view: json parsing failed');
3619
+ return [-1, undefined];
3620
+ }
3621
+ }
3622
+ else if (htmlCode.includes('<JAMESPOT.STUDIO.CODEHTML>')) {
3623
+ try {
3624
+ const startPosCode = htmlCode.indexOf('<JAMESPOT.STUDIO.CODEHTML>') + '<JAMESPOT.STUDIO.CODEHTML>'.length;
3625
+ const endPosCode = htmlCode.indexOf('</JAMESPOT.STUDIO.CODEHTML>');
3626
+ const formItemString = htmlCode.substring(startPosCode, endPosCode);
3627
+ const formItem = JSON.parse(formItemString);
3628
+ const knownIndex = registeredFields.get(formItem === null || formItem === void 0 ? void 0 : formItem.name);
3629
+ if (knownIndex !== undefined) {
3630
+ return [knownIndex, undefined];
3631
+ }
3632
+ const htmlField = createHtmlField(formItem);
3633
+ const indexCreated = appS.fields.push(htmlField) - 1;
3634
+ registeredFields.set(htmlField.id, indexCreated);
3635
+ return [indexCreated, undefined];
3636
+ }
3637
+ catch (_) {
3638
+ console.error('error while parsing studio installed codehtml attr in a view: json parsing failed');
3639
+ return [-1, undefined];
3640
+ }
3641
+ }
3642
+ else {
3643
+ console.error('error while parsing studio installed html attr in a view: unknown html format');
3644
+ return [-1, undefined];
3645
+ }
3646
+ }
3647
+ else if (viewComponent.element === 'image') {
3648
+ const knownIndex = registeredFields.get('image');
3649
+ if (knownIndex !== undefined) {
3650
+ return [knownIndex, undefined];
3651
+ }
3652
+ const imageField = createImageField();
3653
+ const indexCreated = appS.fields.push(imageField) - 1;
3654
+ registeredFields.set('image', indexCreated);
3655
+ return [indexCreated, undefined];
3656
+ }
3657
+ else if (viewComponent.element === 'publishTo') {
3658
+ return [-1, { ref: 'publishTo', fixedValue: undefined }];
3659
+ }
3660
+ else {
3661
+ console.error('error while parsing studio installed attr in a view: unknown attr :O');
3662
+ return [-1, undefined];
3663
+ }
3664
+ }
3665
+ function createStudioDefinedField(appS, ref, tables, state) {
3666
+ const installedField = getInstalledField(ref, tables);
3667
+ const type = getFormItemType(installedField);
3668
+ const v2Field = (function createField() {
3669
+ switch (type) {
3670
+ case AppFormItemTypes.ADDFILEATTACHMENT:
3671
+ return createAddfileattachmentField(installedField);
3672
+ case AppFormItemTypes.NUMBER:
3673
+ return createNumberField(installedField);
3674
+ case AppFormItemTypes.TAGS:
3675
+ return createTagsField(installedField);
3676
+ case AppFormItemTypes.SELECT:
3677
+ return createSelectField(installedField);
3678
+ case AppFormItemTypes.RADIO:
3679
+ return createRadioField(installedField);
3680
+ case AppFormItemTypes.CHECKBOX:
3681
+ return createCheckboxField(installedField);
3682
+ case AppFormItemTypes.CONTENTLINK:
3683
+ return createContentLinkField(installedField, state);
3684
+ case AppFormItemTypes.DESCRIPTION:
3685
+ return createDescriptionField(installedField);
3686
+ case AppFormItemTypes.TEXTAREAHTML:
3687
+ return createTextareaHTMLField(installedField);
3688
+ case AppFormItemTypes.DATE:
3689
+ return createDateField(installedField);
3690
+ case AppFormItemTypes.DATETIME:
3691
+ return createDatetimeField(installedField);
3692
+ case AppFormItemTypes.URL:
3693
+ return createUrlField(installedField);
3694
+ case AppFormItemTypes.EMAIL:
3695
+ return createEmailField(installedField);
3696
+ case AppFormItemTypes.TOGGLE:
3697
+ return createToggleField(installedField);
3698
+ case AppFormItemTypes.USERLINK:
3699
+ return createUserLinkField(installedField);
3700
+ case AppFormItemTypes.TEXTAREA:
3701
+ return createTextAreaField(installedField);
3702
+ case AppFormItemTypes.TEXT:
3703
+ default:
3704
+ return createTextField(installedField);
3705
+ }
3706
+ })();
3707
+ const index = appS.fields.push(v2Field) - 1;
3708
+ return [ref, index];
3709
+ }
3710
+ function getInstalledField(ref, tables) {
3711
+ var _a;
3712
+ let foundField = undefined;
3713
+ for (let i = 0; i < tables.length && !foundField; i++) {
3714
+ foundField = (_a = tables[i]) === null || _a === void 0 ? void 0 : _a.attributes.find((attr) => {
3715
+ return attr.name === ref;
3716
+ });
3717
+ }
3718
+ if (!foundField) {
3719
+ throw new Error('error converting installed app to V2: installed field not found in tables ' + ref);
3720
+ }
3721
+ return foundField;
3722
+ }
3723
+ function addFieldToView(viewName, field, appS, index, fixedInfo) {
3724
+ var _a;
3725
+ if (field.views) {
3726
+ field.views[viewName] = true;
3727
+ appS.views[viewName][field.id] = {
3728
+ type: field.type,
3729
+ properties: field.properties || [],
3730
+ isUsed: true,
3731
+ isOptional: false,
3732
+ isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
3733
+ isFixed: false,
3734
+ value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : null,
3735
+ pos: index,
3736
+ };
3737
+ }
3738
+ }
3739
+ function getFormItemType(installedField) {
3740
+ var _a, _b, _c;
3741
+ switch (installedField.widget.type) {
3742
+ case 'number':
3743
+ return AppFormItemTypes.NUMBER;
3744
+ case 'taxonomy':
3745
+ return AppFormItemTypes.TAGS;
3746
+ case 'date':
3747
+ return AppFormItemTypes.DATE;
3748
+ case 'datetime':
3749
+ return AppFormItemTypes.DATETIME;
3750
+ case 'select':
3751
+ return AppFormItemTypes.SELECT;
3752
+ case 'radio':
3753
+ return AppFormItemTypes.RADIO;
3754
+ case 'url':
3755
+ return AppFormItemTypes.URL;
3756
+ case 'email':
3757
+ return AppFormItemTypes.EMAIL;
3758
+ case 'file':
3759
+ return AppFormItemTypes.ADDFILEATTACHMENT;
3760
+ case 'checkbox':
3761
+ if (((_a = installedField.widget.options) === null || _a === void 0 ? void 0 : _a['1']) === 'GLOBAL_Yes') {
3762
+ return AppFormItemTypes.TOGGLE;
3763
+ }
3764
+ return AppFormItemTypes.CHECKBOX;
3765
+ case 'uri':
3766
+ if (((_b = installedField.widget.params) === null || _b === void 0 ? void 0 : _b.views) === 'user') {
3767
+ return AppFormItemTypes.USERLINK;
3768
+ }
3769
+ if (((_c = installedField.widget.params) === null || _c === void 0 ? void 0 : _c.views) === 'article') {
3770
+ return AppFormItemTypes.CONTENTLINK;
3771
+ }
3772
+ break;
3773
+ case 'textarea':
3774
+ if (installedField.attrType === 'longtext') {
3775
+ return AppFormItemTypes.TEXTAREA;
3776
+ }
3777
+ if (installedField.attrType === 'html') {
3778
+ if (installedField.name === 'description') {
3779
+ return AppFormItemTypes.DESCRIPTION;
3780
+ }
3781
+ return AppFormItemTypes.TEXTAREAHTML;
3782
+ }
3783
+ break;
3784
+ case 'text':
3785
+ return AppFormItemTypes.TEXT;
3786
+ }
3787
+ throw new Error('error converting installed app to V2: installed field type not recognized for field ' + installedField.name);
3788
+ }
3789
+ function addTitleToView(newName, appS, fixedInfo) {
3790
+ var _a;
3791
+ const fieldId = 'title';
3792
+ appS.views[newName][fieldId] = {
3793
+ type: ExtraAppFieldsItemViews.TITLE,
3794
+ properties: [],
3795
+ isUsed: true,
3796
+ isOptional: false,
3797
+ isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
3798
+ isFixed: true,
3799
+ value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : null,
3800
+ pos: 0,
3801
+ };
3802
+ }
3803
+ function addAlertAuthorToView(newName, appS, fixedInfo) {
3804
+ const fieldId = 'alertAuthor';
3805
+ appS.views[newName][fieldId] = {
3806
+ type: ExtraAppFieldsItemViews.RECEIVEACOPY,
3807
+ properties: [],
3808
+ isUsed: true,
3809
+ isOptional: true,
3810
+ isLockedValue: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined,
3811
+ isFixed: false,
3812
+ value: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined ? fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue : true,
3813
+ pos: 300,
3814
+ };
3815
+ }
3816
+ function addSendAlertToView(newName, appS, fixedInfo) {
3817
+ const fieldId = 'sendAlert';
3818
+ appS.views[newName][fieldId] = {
3819
+ type: ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS,
3820
+ properties: [],
3821
+ isUsed: true,
3822
+ isOptional: true,
3823
+ isLockedValue: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined,
3824
+ isFixed: false,
3825
+ value: (fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== undefined ? fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue : true,
3826
+ pos: 200,
3827
+ };
3828
+ }
3829
+ function addPublishToToView(newName, appS, fixedInfo) {
3830
+ var _a;
3831
+ const fieldId = 'publishTo';
3832
+ appS.views[newName][fieldId] = {
3833
+ type: ExtraAppFieldsItemViews.PUBLISHTO,
3834
+ properties: [],
3835
+ isUsed: true,
3836
+ isOptional: true,
3837
+ isLockedValue: !!(fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue),
3838
+ isFixed: false,
3839
+ value: (_a = fixedInfo === null || fixedInfo === void 0 ? void 0 : fixedInfo.fixedValue) !== null && _a !== void 0 ? _a : [],
3840
+ pos: 100,
3841
+ };
3842
+ }
3843
+ function addUserToView(newName, appS) {
3844
+ const fieldId = 'user';
3845
+ appS.views[newName][fieldId] = {
3846
+ type: ExtraAppFieldsItemViews.USER,
3847
+ properties: [],
3848
+ isUsed: true,
3849
+ isOptional: false,
3850
+ isLockedValue: false,
3851
+ isFixed: true,
3852
+ value: null,
3853
+ pos: 1,
3854
+ };
3855
+ }
3856
+ function addDateCreationToView(newName, appS) {
3857
+ const fieldId = 'dateCreation';
3858
+ appS.views[newName][fieldId] = {
3859
+ type: ExtraAppFieldsItemViews.CREATIONDATE,
3860
+ properties: [],
3861
+ isUsed: true,
3862
+ isOptional: true,
3863
+ isLockedValue: false,
3864
+ isFixed: false,
3865
+ value: null,
3866
+ pos: 100,
3867
+ };
3868
+ }
3869
+
3870
+ function InstalledAppStudioAdapter(serverApp, serverApps, state) {
3136
3871
  var _a, _b, _c, _d;
3137
3872
  const { version, dateCreation } = serverApp.manifest;
3138
3873
  const appTypeServer = serverApp.typeModel;
3139
3874
  const views = Object.assign({}, ...viewsList.map((view) => ({
3140
- [view]: [],
3875
+ [view]: {},
3141
3876
  })));
3142
3877
  const studioApp = {
3143
3878
  idApp: serverApp.idApp,
3144
3879
  status: _formatStatus(serverApp),
3145
3880
  studioVersion: 2,
3146
- manifest: Object.assign({ appShortName: serverApp.name, appName: serverApp.label, description: serverApp.description, author: serverApp.author, cssColor: (_a = appTypeServer.cssColor) !== null && _a !== void 0 ? _a : '#392994', cssClass: { label: (_b = appTypeServer.cssClass) !== null && _b !== void 0 ? _b : 'star', value: (_c = appTypeServer.cssClass) !== null && _c !== void 0 ? _c : 'star' }, version: version, dateCreation: dateCreation, checkAccess: serverApp.checkAccess, attrExposed: serverApp.attrExposed, viewSolr: serverApp.view, typeLabel: (_d = appTypeServer.typeLabel) !== null && _d !== void 0 ? _d : {} }, (serverApp.articlesCount && { articlesCount: serverApp.articlesCount })),
3881
+ manifest: {
3882
+ appShortName: serverApp.label,
3883
+ appName: serverApp.label,
3884
+ description: serverApp.description,
3885
+ author: serverApp.author,
3886
+ cssColor: (_a = appTypeServer.cssColor) !== null && _a !== void 0 ? _a : '#392994',
3887
+ cssClass: { label: (_b = appTypeServer.cssClass) !== null && _b !== void 0 ? _b : 'star', value: (_c = appTypeServer.cssClass) !== null && _c !== void 0 ? _c : 'star' },
3888
+ version: version,
3889
+ dateCreation: dateCreation,
3890
+ checkAccess: false,
3891
+ accessRightList: "",
3892
+ attrExposed: [],
3893
+ viewSolr: serverApp.view ? STUDIO_VIEW.SOLR : STUDIO_VIEW.NOT_SOLR,
3894
+ typeLabel: appTypeServer.typeLabel,
3895
+ articlesCount: (_d = serverApp.articlesCount) !== null && _d !== void 0 ? _d : 0,
3896
+ },
3147
3897
  fields: [],
3148
3898
  views,
3149
- installFor: serverApp.accessRightObjectList,
3899
+ installFor: serverApp.accessRightObjectList ? buildAudience(serverApp.accessRightObjectList) : [],
3150
3900
  audience: serverApp.checkAccess === false ? AUDIENCE.ALL : AUDIENCE.CUSTOM,
3151
3901
  };
3902
+ populateFieldsAndViews(serverApp, studioApp, state);
3903
+ studioApp.views = updateViewsFromFields(studioApp, studioApp.fields);
3152
3904
  const inWorkAppVersion = _findAssociatedDraft(serverApp.idApp, serverApps);
3153
3905
  if (!inWorkAppVersion)
3154
3906
  return studioApp;
@@ -3170,12 +3922,13 @@ function DraftAppStudioAdapter(serverApp) {
3170
3922
  manifest: parsedJson.manifest,
3171
3923
  fields: parsedJson.fields,
3172
3924
  views: parsedJson.views,
3925
+ syncViewFieldOrder: parsedJson.syncViewFieldOrder,
3173
3926
  audience: parsedJson.audience,
3174
3927
  installFor: parsedJson.installFor,
3175
3928
  };
3176
3929
  }
3177
3930
  else {
3178
- return Object.assign(Object.assign({}, migrateJson(JSON.parse(serverApp.value))), { status: _formatStatus(serverApp) });
3931
+ return Object.assign(Object.assign({}, migrateJson(parsedJson)), { status: _formatStatus(serverApp), migratedFrom: 1 });
3179
3932
  }
3180
3933
  }
3181
3934
  function _formatStatus(serverApp) {
@@ -3192,11 +3945,11 @@ function _findAssociatedDraft(idApp, serverApps) {
3192
3945
  function _findAssociatedInstalled(idApp, serverApps) {
3193
3946
  return !!serverApps.find((app) => app.idApp === idApp && app.status === StudioApplicationStatus.installed);
3194
3947
  }
3195
- function serverAppsToStudioApps(serverApps) {
3948
+ function serverAppsToStudioApps(serverApps, state) {
3196
3949
  const studioApps = serverApps
3197
3950
  .map((serverApp) => {
3198
3951
  if (serverApp.status === StudioApplicationStatus.installed) {
3199
- return InstalledAppStudioAdapter(serverApp, serverApps);
3952
+ return InstalledAppStudioAdapter(serverApp, serverApps, state);
3200
3953
  }
3201
3954
  else {
3202
3955
  if (_findAssociatedInstalled(serverApp.idApp, serverApps))
@@ -3262,7 +4015,13 @@ function renderAppView(viewSolr, listView) {
3262
4015
  if (viewSolr === STUDIO_VIEW.SOLR) {
3263
4016
  let xml = '<AppView>solr</AppView>';
3264
4017
  const formItemIdInList = [];
3265
- Object.entries(listView).forEach(([fieldId, field]) => {
4018
+ Object.entries(listView).sort((a, b) => a[1].pos - b[1].pos).forEach(([fieldId, field]) => {
4019
+ if (!field.isUsed) {
4020
+ return;
4021
+ }
4022
+ if ([AppFormItemTypes.IMAGE].includes(field.type)) {
4023
+ return;
4024
+ }
3266
4025
  formItemIdInList.push(getAttrNameFormItem(field, fieldId));
3267
4026
  });
3268
4027
  xml += `<AppColumns>${formItemIdInList.join()}</AppColumns>`;
@@ -3272,8 +4031,12 @@ function renderAppView(viewSolr, listView) {
3272
4031
  }
3273
4032
  function renderAppSearch(searchView) {
3274
4033
  const formItemIdInFilter = [];
3275
- Object.entries(searchView).forEach(([fieldId, field]) => {
3276
- if (![ExtraAppFieldsItemViews.TITLE, AppFormItemTypes.IMAGE].includes(field.type))
4034
+ Object.entries(searchView).sort((a, b) => a[1].pos - b[1].pos).forEach(([fieldId, field]) => {
4035
+ if (!field.isUsed) {
4036
+ return;
4037
+ }
4038
+ const list = [ExtraAppFieldsItemViews.TITLE, AppFormItemTypes.IMAGE];
4039
+ if (!list.includes(field.type))
3277
4040
  formItemIdInFilter.push(getAttrNameFormItem(field, fieldId));
3278
4041
  });
3279
4042
  return `<AttrExposed>${formItemIdInFilter.join()}</AttrExposed>`;
@@ -3308,13 +4071,13 @@ function renderAudience(audience, installFor) {
3308
4071
  return '';
3309
4072
  }
3310
4073
  function renderPrimaryFields(fields) {
3311
- const primaryFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => AppFormPrimaryList.includes(field.type));
4074
+ const primaryFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => AppFormPrimaryListValues.includes(field.type));
3312
4075
  if (primaryFields.length === 0)
3313
4076
  return '';
3314
4077
  return `<primaryFields>${primaryFields.map((field) => formItem2xml(field)).join('')}</primaryFields>`;
3315
4078
  }
3316
4079
  function renderCustomFields(fields) {
3317
- const customFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => !AppFormPrimaryList.includes(field.type));
4080
+ const customFields = fields === null || fields === void 0 ? void 0 : fields.filter((field) => !AppFormPrimaryListValues.includes(field.type));
3318
4081
  const filteredCustomFields = customFields === null || customFields === void 0 ? void 0 : customFields.filter((field) => field.type !== AppFormItemTypes.IMAGE);
3319
4082
  if (filteredCustomFields.length === 0)
3320
4083
  return '';
@@ -3380,14 +4143,20 @@ function renderWidget(fieldType, fieldProperties) {
3380
4143
  const isMultiple = optionEditor.value.canSelectMultiple;
3381
4144
  const options = optionEditor.value.propertyOptions;
3382
4145
  const hasDefaultValue = optionEditor.value.defaultSelectOption;
3383
- const defaultValue = optionEditor.value.defaultSelectOptionValue;
4146
+ const defaultValue = optionEditor.value.defaultSelectOptionValue.value;
4147
+ const userCanModifiyByComment = optionEditor.value.userCanModifiyByComment;
3384
4148
  return `<widget form="select" ${isMultiple ? 'multiple="1"' : ''}>
3385
4149
  <options>
3386
4150
  ${options
3387
4151
  .map((option) => `<option value="${option.value}" label="${option.title}"></option>`)
3388
4152
  .join('')}
3389
4153
  </options>
3390
- ${hasDefaultValue ? `<params><param key="defaultValue" value="${defaultValue}"/></params>` : ''}
4154
+ ${hasDefaultValue || userCanModifiyByComment
4155
+ ? `<params>
4156
+ ${hasDefaultValue ? `<param key="defaultValue" value="${defaultValue}"/>` : ''}
4157
+ ${userCanModifiyByComment ? `<param key="explain" value="1"/>` : ''}
4158
+ </params>`
4159
+ : ''}
3391
4160
  </widget>`;
3392
4161
  }
3393
4162
  case AppFormItemTypes.RADIO: {
@@ -3526,9 +4295,7 @@ function renderFieldTypeToXmlType(fieldType) {
3526
4295
  case AppFormItemTypes.TAGS:
3527
4296
  return 'taxonomy';
3528
4297
  case AppFormItemTypes.TEXT:
3529
- case AppFormItemTypes.SELECT:
3530
4298
  case AppFormItemTypes.RADIO:
3531
- case AppFormItemTypes.CHECKBOX:
3532
4299
  case AppFormItemTypes.URL:
3533
4300
  case AppFormItemTypes.EMAIL:
3534
4301
  case AppFormItemTypes.ADDFILEATTACHMENT:
@@ -3537,6 +4304,8 @@ function renderFieldTypeToXmlType(fieldType) {
3537
4304
  case AppFormItemTypes.CONTENTLINK:
3538
4305
  return 'text';
3539
4306
  case AppFormItemTypes.TEXTAREA:
4307
+ case AppFormItemTypes.CHECKBOX:
4308
+ case AppFormItemTypes.SELECT:
3540
4309
  return 'longtext';
3541
4310
  case AppFormItemTypes.DATE:
3542
4311
  return 'date';
@@ -3577,7 +4346,9 @@ function renderDisplays(studioApp) {
3577
4346
  let toRet = '';
3578
4347
  Object.entries(studioApp.views).forEach(([viewName, viewContent]) => {
3579
4348
  if (Object.prototype.hasOwnProperty.call(internal2XmlView, viewName)) {
3580
- const viewField = Object.entries(viewContent);
4349
+ const viewField = Object.entries(viewContent)
4350
+ .filter((a) => a[1].isUsed)
4351
+ .sort((a, b) => a[1].pos - b[1].pos);
3581
4352
  toRet += `<display view="${internal2XmlView[viewName]}" mode="${viewName === 'view' ? 'view' : 'form'}">
3582
4353
  ${viewField.map(([fieldId, view]) => renderDisplayAttr(fieldId, view)).join('')}
3583
4354
  </display>`;
@@ -3629,16 +4400,21 @@ function renderDisplayAttr(fieldId, view) {
3629
4400
  xml += `<input type="hidden" name="${attrName}[]" value=${JSON.stringify(view.value.uri)}>`;
3630
4401
  }
3631
4402
  else if (view.type === AppFormItemTypes.SELECT) {
3632
- const values = view.value;
3633
4403
  const canSelectMultiple = (_a = view.properties.find((property) => property.propertyType === AppFieldFormPropertyTypes.OPTIONS_EDITOR)) === null || _a === void 0 ? void 0 : _a.value.canSelectMultiple;
3634
- values.forEach((value) => {
3635
- xml += `<input type="hidden" name="${attrName}${canSelectMultiple ? '[]' : ''}" value="${value.value}">`;
3636
- });
4404
+ if (canSelectMultiple) {
4405
+ const values = view.value;
4406
+ values.forEach((value) => {
4407
+ xml += `<input type="hidden" name="${attrName}[]" value="${value.value}">`;
4408
+ });
4409
+ }
4410
+ else {
4411
+ xml += `<input type="hidden" name="${attrName}" value="${view.value.value}">`;
4412
+ }
3637
4413
  }
3638
4414
  else if (view.type === AppFormItemTypes.CHECKBOX) {
3639
4415
  const values = view.value;
3640
4416
  values.forEach((value) => {
3641
- xml += `<input type="hidden" name="${attrName}[]" value="${value.value}">`;
4417
+ xml += `<input type="hidden" name="${attrName}[]" value="${value}">`;
3642
4418
  });
3643
4419
  }
3644
4420
  else if (view.type === AppFormItemTypes.DATE) {
@@ -3652,21 +4428,28 @@ function renderDisplayAttr(fieldId, view) {
3652
4428
  }
3653
4429
  else if (view.type === AppFormItemTypes.DATETIME) {
3654
4430
  const dateValue = new Date(view.value);
3655
- const xmlFixedValue = [
4431
+ const xmlFixedValue = `${[
3656
4432
  pad(dateValue.getDate()),
3657
4433
  pad(dateValue.getMonth() + 1),
3658
4434
  dateValue.getFullYear(),
3659
- pad(dateValue.getHours()),
3660
- pad(dateValue.getMinutes()),
3661
- pad(dateValue.getSeconds()),
3662
- ].join('/');
4435
+ ].join('/')} ${pad(dateValue.getHours())}:${pad(dateValue.getMinutes())}:${pad(dateValue.getSeconds())}`;
3663
4436
  xml += '<input type="hidden" name="' + attrName + '" value="' + xmlFixedValue + '">';
3664
4437
  }
3665
4438
  else if (view.type === AppFormItemTypes.TAGS) {
3666
4439
  xml += `<input type="hidden" name="${attrName}" value="${(_c = (_b = view.value) === null || _b === void 0 ? void 0 : _b.map((v) => v.uri)) === null || _c === void 0 ? void 0 : _c.join(',')}">`;
3667
4440
  }
3668
4441
  else if (view.type === AppFormItemTypes.DESCRIPTION || view.type === AppFormItemTypes.TEXTAREAHTML) {
3669
- xml += `<input type="hidden" name="${attrName}" value="${view.value.html}">`;
4442
+ xml += `<input type="hidden" name="${attrName}" value="${view.value}">`;
4443
+ }
4444
+ else if (view.type === ExtraAppFieldsItemViews.RECEIVEACOPY) {
4445
+ if (view.value) {
4446
+ xml += `<input type="hidden" name="alertAuthor[jamespot]"><input type="hidden" name="alertAuthor[]" value="1">`;
4447
+ }
4448
+ }
4449
+ else if (view.type === ExtraAppFieldsItemViews.SENDALERTTOSUBSCRIBERS) {
4450
+ if (view.value) {
4451
+ xml += `<input type="hidden" name="sendAlert[jamespot]"><input type="hidden" name="sendAlert[]" value="1">`;
4452
+ }
3670
4453
  }
3671
4454
  else {
3672
4455
  xml += `<input type="hidden" name="${attrName}" value="${view.value}">`;
@@ -3676,7 +4459,14 @@ function renderDisplayAttr(fieldId, view) {
3676
4459
  else {
3677
4460
  switch (view.type) {
3678
4461
  case AppFormItemTypes.CODEHTML: {
3679
- xml += `<html><![CDATA[ <!-- <JAMESPOT.STUDIO.CODEHTML>${view.value}</JAMESPOT.STUDIO.CODEHTML><JAMESPOT.STUDIO.FIELD_POS>${view.pos}</JAMESPOT.STUDIO.FIELD_POS>-->${view.value}]]></html>`;
4462
+ const fieldToInclude = {
4463
+ id: fieldId,
4464
+ name: fieldId,
4465
+ properties: {
4466
+ code: view.value,
4467
+ },
4468
+ };
4469
+ xml += `<html><![CDATA[ <!-- <JAMESPOT.STUDIO.CODEHTML>${JSON.stringify(fieldToInclude)}</JAMESPOT.STUDIO.CODEHTML><JAMESPOT.STUDIO.FIELD_POS>${view.pos}</JAMESPOT.STUDIO.FIELD_POS>-->${view.value}]]></html>`;
3680
4470
  break;
3681
4471
  }
3682
4472
  case AppFormItemTypes.IMAGE:
@@ -3703,12 +4493,12 @@ const initialState$1 = {
3703
4493
  installStudioAppStatus: 'idle',
3704
4494
  hasChanged: false,
3705
4495
  };
3706
- const fetchCurrentStudioApp = createAsyncThunk('studio/fetchCurrentStudioApp', ({ idApp, status }, { extra, rejectWithValue }) => __awaiter(void 0, void 0, void 0, function* () {
4496
+ const fetchCurrentStudioApp = createAsyncThunk('studio/fetchCurrentStudioApp', ({ idApp, status }, { extra, rejectWithValue, getState }) => __awaiter(void 0, void 0, void 0, function* () {
3707
4497
  const jApi = extra.jApi;
3708
4498
  const error = { error: 1, errorMsg: 'Error fetching application' };
3709
4499
  try {
3710
4500
  const studioApplicationBase = (yield jApi.application.get(idApp, status)).result;
3711
- const studioApplication = serverAppsToStudioApps([studioApplicationBase])[0];
4501
+ const studioApplication = serverAppsToStudioApps([studioApplicationBase], getState())[0];
3712
4502
  if (!studioApplication) {
3713
4503
  return rejectWithValue(error);
3714
4504
  }
@@ -3812,16 +4602,22 @@ const CurrentStudioAppSlice = createSlice({
3812
4602
  },
3813
4603
  });
3814
4604
 
3815
- function cloneStudioAppFromExistingApp(existingApp, author) {
3816
- const newApp = existingApp.inWorkVersion
3817
- ? JSON.parse(JSON.stringify(existingApp.inWorkVersion))
4605
+ function cloneStudioAppFromExistingApp(existingApp, author, inWorkVersion) {
4606
+ const newApp = existingApp.studioVersion !== 2
4607
+ ? JSON.parse(JSON.stringify(migrateJson(existingApp)))
3818
4608
  : JSON.parse(JSON.stringify(existingApp));
3819
- const newAppId = v4();
3820
- const newAppName = `${existingApp.manifest.appName} Copie`;
3821
- newApp.idApp = newAppId;
3822
- newApp.status = APP_STATUS_TYPE.DRAFT;
3823
- newApp.manifest = Object.assign(Object.assign({}, newApp.manifest), { appName: newAppName, appShortName: newAppName, author: author || '', dateCreation: new Date().toISOString(), version: 0.1, articlesCount: 0 });
3824
- return [newApp, newAppId];
4609
+ delete newApp.inWorkVersion;
4610
+ if (!inWorkVersion) {
4611
+ const newAppId = v4();
4612
+ const newAppName = `${existingApp.manifest.appName} Copie`;
4613
+ newApp.idApp = newAppId;
4614
+ newApp.status = APP_STATUS_TYPE.DRAFT;
4615
+ newApp.manifest = Object.assign(Object.assign({}, newApp.manifest), { appName: newAppName, appShortName: newAppName, author: author || newApp.manifest.author || '', dateCreation: new Date().toISOString(), version: 0.1, articlesCount: 0 });
4616
+ }
4617
+ else {
4618
+ newApp.manifest.version = newApp.manifest.version + 0.1;
4619
+ }
4620
+ return [newApp, newApp.idApp];
3825
4621
  }
3826
4622
 
3827
4623
  function createNewStudioApp$1({ author, appName }) {
@@ -3883,37 +4679,78 @@ function createNewStudioApp$1({ author, appName }) {
3883
4679
  attrExposed: [],
3884
4680
  articlesCount: 0,
3885
4681
  },
4682
+ syncViewFieldOrder: {
4683
+ create: true,
4684
+ popup: true,
4685
+ view: true,
4686
+ edit: true,
4687
+ list: true,
4688
+ filter: true,
4689
+ },
3886
4690
  fields: [],
3887
4691
  views,
3888
- audience: AUDIENCE.ALL,
4692
+ audience: AUDIENCE.CUSTOM,
3889
4693
  installFor: [],
3890
4694
  },
3891
4695
  };
3892
4696
  }
3893
4697
 
4698
+ function appLexicalSort(a, b) {
4699
+ return a.manifest.appName > b.manifest.appName ? 1 : -1;
4700
+ }
3894
4701
  const initialState = {
3895
4702
  loadingStudioAppsList: 'idle',
3896
4703
  deleteStudioAppStatus: 'idle',
3897
4704
  suspendStudioAppStatus: 'idle',
3898
4705
  restartStudioAppStatus: 'idle',
3899
4706
  cloneStudioAppStatus: 'idle',
4707
+ createInWorkAppStatus: 'idle',
3900
4708
  createNewStudioAppStatus: 'idle',
3901
4709
  };
3902
- const fetchStudioAppsList = createAsyncThunk('studio/appsList', (_, { extra, rejectWithValue, dispatch }) => __awaiter(void 0, void 0, void 0, function* () {
4710
+ const fetchStudioAppsList = createAsyncThunk('studio/appsList', (intl, { extra, rejectWithValue, dispatch, getState }) => __awaiter(void 0, void 0, void 0, function* () {
3903
4711
  const jApi = extra.jApi;
3904
4712
  try {
3905
4713
  const { result } = yield jApi.application.list();
3906
- return yield Promise.all(result.map((app) => __awaiter(void 0, void 0, void 0, function* () {
4714
+ const taxonomies = yield jApi.taxonomy.list();
4715
+ const apps = yield Promise.all(result.map((app) => __awaiter(void 0, void 0, void 0, function* () {
3907
4716
  const coreApp = (yield jApi.application.get(app.idApp, app.status)).result;
3908
4717
  const articlesCount = (yield jApi.article.count(app.idApp)).result;
3909
4718
  return Object.assign(Object.assign({}, coreApp), { articlesCount });
3910
4719
  })));
4720
+ const transformedApps = serverAppsToStudioApps(apps, getState());
4721
+ transformedApps.forEach((app) => __awaiter(void 0, void 0, void 0, function* () {
4722
+ app.fields = updateTaxonomies(app.fields, taxonomies, intl);
4723
+ if (app.inWorkVersion) {
4724
+ app.inWorkVersion.fields = updateTaxonomies(app.inWorkVersion.fields, taxonomies, intl);
4725
+ }
4726
+ }));
4727
+ return transformedApps;
3911
4728
  }
3912
4729
  catch (_) {
3913
4730
  dispatch(Toast.actions.error({ label: 'GLOBAL_Technical_Error' }));
3914
4731
  throw rejectWithValue({ error: 1, errorMsg: 'Error retrieving applications' });
3915
4732
  }
3916
4733
  }));
4734
+ function updateTaxonomies(fields, taxonomies, intl) {
4735
+ return fields.map((field) => {
4736
+ var _a;
4737
+ if (field.type !== AppFormItemTypes.TAGS) {
4738
+ return field;
4739
+ }
4740
+ const newField = JSON.parse(JSON.stringify(field));
4741
+ const newFieldTaxoProp = (_a = newField.properties) === null || _a === void 0 ? void 0 : _a.find((prop) => {
4742
+ return prop.propertyType === AppFieldFormPropertyTypes.TAXONOMY;
4743
+ });
4744
+ const taxo = taxonomies.find((taxo) => {
4745
+ return taxo.id === (newFieldTaxoProp === null || newFieldTaxoProp === void 0 ? void 0 : newFieldTaxoProp.value.id);
4746
+ });
4747
+ if (taxo && newFieldTaxoProp) {
4748
+ newFieldTaxoProp.value.title = intl.formatMessage({ id: taxo.title });
4749
+ newFieldTaxoProp.value.type = taxo.type;
4750
+ }
4751
+ return newField;
4752
+ });
4753
+ }
3917
4754
  const createNewStudioApp = createAsyncThunk('studio/createApp', ({ appName, callback }, { extra, dispatch, rejectWithValue, getState }) => __awaiter(void 0, void 0, void 0, function* () {
3918
4755
  var _a;
3919
4756
  const jApi = extra.jApi;
@@ -3966,12 +4803,20 @@ const restartStudioApp = createAsyncThunk('studio/restartStudioApp', ({ idApp },
3966
4803
  throw rejectWithValue({ error: 1, errorMsg: 'Error restarting application' });
3967
4804
  }
3968
4805
  }));
3969
- const cloneStudioApp = createAsyncThunk('studio/cloneStudioApp', ({ idApp }, { extra, getState, rejectWithValue, dispatch }) => __awaiter(void 0, void 0, void 0, function* () {
4806
+ const cloneStudioApp = createAsyncThunk('studio/cloneStudioApp', ({ idApp, inWork }, { extra, getState, rejectWithValue, dispatch }) => __awaiter(void 0, void 0, void 0, function* () {
3970
4807
  var _b, _c;
3971
4808
  const jApi = extra.jApi;
3972
- const existingStudioApp = (_b = getState().studio.studioAppsList.studioAppsList) === null || _b === void 0 ? void 0 : _b.find((app) => app.idApp === idApp);
4809
+ let existingStudioApp = (_b = getState().studio.studioAppsList.studioAppsList) === null || _b === void 0 ? void 0 : _b.find((app) => app.idApp === idApp);
3973
4810
  if (!existingStudioApp)
3974
4811
  return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
4812
+ if (inWork) {
4813
+ if (existingStudioApp.inWorkVersion !== undefined) {
4814
+ existingStudioApp = existingStudioApp.inWorkVersion;
4815
+ }
4816
+ else {
4817
+ return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
4818
+ }
4819
+ }
3975
4820
  const currentUser = (_c = getState().userCurrent) === null || _c === void 0 ? void 0 : _c.uri;
3976
4821
  const [clonedStudioApp, newAppId] = cloneStudioAppFromExistingApp(existingStudioApp, currentUser);
3977
4822
  const clonedStudioAppReady = JSON.stringify(clonedStudioApp);
@@ -3985,12 +4830,33 @@ const cloneStudioApp = createAsyncThunk('studio/cloneStudioApp', ({ idApp }, { e
3985
4830
  return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
3986
4831
  }
3987
4832
  }));
4833
+ const createInWorkStudioApp = createAsyncThunk('studio/createInWorkStudioApp', ({ idApp }, { extra, getState, rejectWithValue, dispatch }) => __awaiter(void 0, void 0, void 0, function* () {
4834
+ var _d, _e;
4835
+ const jApi = extra.jApi;
4836
+ const existingStudioApp = (_d = getState().studio.studioAppsList.studioAppsList) === null || _d === void 0 ? void 0 : _d.find((app) => app.idApp === idApp);
4837
+ if (!existingStudioApp ||
4838
+ ![APP_STATUS_TYPE.INSTALLED, APP_STATUS_TYPE.SUSPENDED].includes(existingStudioApp.status)) {
4839
+ return rejectWithValue({ error: 1, errorMsg: 'Error cloning application' });
4840
+ }
4841
+ const currentUser = (_e = getState().userCurrent) === null || _e === void 0 ? void 0 : _e.uri;
4842
+ const [clonedStudioApp, newAppId] = cloneStudioAppFromExistingApp(existingStudioApp, currentUser, true);
4843
+ const clonedStudioAppReady = JSON.stringify(clonedStudioApp);
4844
+ try {
4845
+ yield jApi.application.save(newAppId, clonedStudioAppReady, 'saved');
4846
+ dispatch(Toast.actions.success({ label: 'APPSTUDIO_AppItem_CreateInWork' }));
4847
+ return clonedStudioApp;
4848
+ }
4849
+ catch (_) {
4850
+ dispatch(Toast.actions.error({ label: 'GLOBAL_Technical_Error' }));
4851
+ return rejectWithValue({ error: 1, errorMsg: 'Error creating in work version for application' });
4852
+ }
4853
+ }));
3988
4854
  const StudioAppsListSlice = createSlice({
3989
4855
  name: 'studioAppsList',
3990
4856
  initialState,
3991
4857
  reducers: {
3992
4858
  setAppsList: (state, action) => {
3993
- state.studioAppsList = action.payload;
4859
+ state.studioAppsList = [...action.payload].sort(appLexicalSort);
3994
4860
  },
3995
4861
  },
3996
4862
  extraReducers: (builder) => {
@@ -4003,7 +4869,7 @@ const StudioAppsListSlice = createSlice({
4003
4869
  if (state.loadingStudioAppsList === 'pending') {
4004
4870
  state.loadingStudioAppsList = 'idle';
4005
4871
  }
4006
- state.studioAppsList = serverAppsToStudioApps(action.payload);
4872
+ state.studioAppsList = [...action.payload].sort(appLexicalSort);
4007
4873
  })
4008
4874
  .addCase(fetchStudioAppsList.rejected, (state) => {
4009
4875
  if (state.loadingStudioAppsList === 'pending')
@@ -4024,8 +4890,13 @@ const StudioAppsListSlice = createSlice({
4024
4890
  let { status } = action.meta.arg;
4025
4891
  if (status === APP_STATUS_TYPE.INSTALLED)
4026
4892
  status = APP_STATUS_TYPE.SUSPENDED;
4027
- if (app.idApp === idApp && app.status === status)
4893
+ if (app.idApp === idApp && app.status === status) {
4894
+ if (app.inWorkVersion && app.status === APP_STATUS_TYPE.SUSPENDED) {
4895
+ app.inWorkVersion.status = APP_STATUS_TYPE.DRAFT;
4896
+ return [...acc, app.inWorkVersion];
4897
+ }
4028
4898
  return acc;
4899
+ }
4029
4900
  if (app.inWorkVersion &&
4030
4901
  app.inWorkVersion.idApp === idApp &&
4031
4902
  app.inWorkVersion.status === status) {
@@ -4081,38 +4952,65 @@ const StudioAppsListSlice = createSlice({
4081
4952
  })) !== null && _b !== void 0 ? _b : [];
4082
4953
  })
4083
4954
  .addCase(restartStudioApp.rejected, (state) => {
4084
- if (state.restartStudioAppStatus === 'pending')
4955
+ if (state.restartStudioAppStatus === 'pending') {
4085
4956
  state.restartStudioAppStatus = 'idle';
4957
+ }
4086
4958
  })
4087
4959
  .addCase(cloneStudioApp.pending, (state) => {
4088
- if (state.cloneStudioAppStatus === 'idle')
4960
+ if (state.cloneStudioAppStatus === 'idle') {
4089
4961
  state.cloneStudioAppStatus = 'pending';
4962
+ }
4090
4963
  })
4091
4964
  .addCase(cloneStudioApp.fulfilled, (state, action) => {
4092
4965
  var _a;
4093
4966
  if (state.cloneStudioAppStatus === 'pending') {
4094
4967
  state.cloneStudioAppStatus = 'idle';
4095
4968
  }
4096
- state.studioAppsList = [...((_a = state.studioAppsList) !== null && _a !== void 0 ? _a : []), action.payload];
4969
+ state.studioAppsList = [...((_a = state.studioAppsList) !== null && _a !== void 0 ? _a : []), action.payload].sort(appLexicalSort);
4097
4970
  })
4098
4971
  .addCase(cloneStudioApp.rejected, (state) => {
4099
- if (state.cloneStudioAppStatus === 'pending')
4972
+ if (state.cloneStudioAppStatus === 'pending') {
4100
4973
  state.cloneStudioAppStatus = 'idle';
4974
+ }
4975
+ })
4976
+ .addCase(createInWorkStudioApp.pending, (state) => {
4977
+ if (state.createInWorkAppStatus === 'idle') {
4978
+ state.createInWorkAppStatus = 'pending';
4979
+ }
4980
+ })
4981
+ .addCase(createInWorkStudioApp.fulfilled, (state, action) => {
4982
+ var _a;
4983
+ if (state.createInWorkAppStatus === 'pending') {
4984
+ state.createInWorkAppStatus = 'idle';
4985
+ }
4986
+ const app = (_a = state.studioAppsList) === null || _a === void 0 ? void 0 : _a.find((app) => {
4987
+ return app.idApp === action.payload.idApp;
4988
+ });
4989
+ if (app) {
4990
+ app.inWorkVersion = action.payload;
4991
+ }
4992
+ })
4993
+ .addCase(createInWorkStudioApp.rejected, (state) => {
4994
+ if (state.createInWorkAppStatus === 'pending') {
4995
+ state.createInWorkAppStatus = 'idle';
4996
+ }
4101
4997
  })
4102
4998
  .addCase(createNewStudioApp.pending, (state) => {
4103
- if (state.createNewStudioAppStatus === 'idle')
4999
+ if (state.createNewStudioAppStatus === 'idle') {
4104
5000
  state.createNewStudioAppStatus = 'pending';
5001
+ }
4105
5002
  })
4106
5003
  .addCase(createNewStudioApp.fulfilled, (state, action) => {
4107
5004
  var _a;
4108
5005
  if (state.createNewStudioAppStatus === 'pending') {
4109
5006
  state.createNewStudioAppStatus = 'idle';
4110
5007
  }
4111
- state.studioAppsList = [...((_a = state.studioAppsList) !== null && _a !== void 0 ? _a : []), action.payload];
5008
+ state.studioAppsList = [...((_a = state.studioAppsList) !== null && _a !== void 0 ? _a : []), action.payload].sort(appLexicalSort);
4112
5009
  })
4113
5010
  .addCase(createNewStudioApp.rejected, (state) => {
4114
- if (state.createNewStudioAppStatus === 'pending')
5011
+ if (state.createNewStudioAppStatus === 'pending') {
4115
5012
  state.createNewStudioAppStatus = 'idle';
5013
+ }
4116
5014
  });
4117
5015
  },
4118
5016
  });
@@ -4141,12 +5039,17 @@ const studio = {
4141
5039
  createNewStudioApp,
4142
5040
  fetchCurrentStudioApp,
4143
5041
  saveCurrentStudioApp,
4144
- installStudioApp }),
5042
+ installStudioApp,
5043
+ createInWorkStudioApp }),
4145
5044
  selectors: {
4146
5045
  selectStudioAppsList,
4147
5046
  selectCurrentStudioApp,
4148
5047
  },
5048
+ utils: {
5049
+ updateViewsFromFields,
5050
+ generateNewFormField,
5051
+ },
4149
5052
  };
4150
5053
 
4151
- export { APP_STATUS_TYPE, AUDIENCE, Animations, AppColumnsDefaultTypes, AppFieldFormPropertyTypes, AppFormBannedFromViews$1 as AppFormBannedFromViews, AppFormFieldOnlyInView, AppFormFixedList$1 as AppFormFixedList, AppFormItemTypes, AppFormNoAsFieldList, AppFormNonPrimaryList, AppFormPrimaryList, AppFormUniqueList, Application, AssetReservation, Bookmark, Comment, ExtraAppFieldsItemViews, Faq, Hook, MODE_EDIT, MODE_VIEW, MagicPad, MapExtraFieldsWithView, MediaLibrary, Model, Network, Platform, STUDIO_VIEW, Share, SocialActions, StatusType$1 as StatusType, TVDisplay, TinyMCE, Toast, UserCurrent, WedocApp, Widget, WidgetEditor, actions, animationsReducer, animationsSlice, fetchMediaLibraryConfig, fetchMediaLibraryFilesStats, fetchMediaLibraryFolders, fetchMediaLibraryFoldersStats, fetchMediaLibraryStats, fetchMediaLibraryUnclassifiedFiles, fetchPads, jland, magicPadSlice, mediaLibraryReducer, mediaLibrarySlice, slice$1 as slice, studio, updateWidgetContent, viewsList };
5054
+ export { APP_STATUS_TYPE, AUDIENCE, Animations, AppColumnsDefaultTypes, AppFieldFormPropertyTypes, AppFormBannedFromViews$1 as AppFormBannedFromViews, AppFormFieldOnlyInView, AppFormFixedList$1 as AppFormFixedList, AppFormItemTypes, AppFormNoAsFieldList, AppFormNonPrimaryList, AppFormPrimaryList, AppFormPrimaryListValues, AppFormUniqueList, AppFormUniqueListCheck, Application, AssetReservation, Bookmark, Comment, Description, Element, ExtraAppFieldsItemViews, Faq, Hook, MagicPad, MapExtraFieldsWithView, MediaLibrary, Model, Network, Platform, STUDIO_VIEW, Share, SocialActions, StatusType$1 as StatusType, TVDisplay, TinyMCE, Toast, UserCurrent, WedocApp, Widget, WidgetEditor, actions, animationsReducer, animationsSlice, fetchMediaLibraryConfig, fetchMediaLibraryFilesStats, fetchMediaLibraryFolders, fetchMediaLibraryFoldersStats, fetchMediaLibraryStats, fetchMediaLibraryUnclassifiedFiles, fetchPads, jland, magicPadSlice, mediaLibraryReducer, mediaLibrarySlice, slice$1 as slice, studio, updateWidgetContent, viewsList };
4152
5055
  //# sourceMappingURL=esm.js.map