CREATE TABLE public.core_user_groups (
	id bigserial NOT NULL,
	group_name varchar(20) NOT NULL,
    group_type varchar(5) NOT NULL,
	email varchar(255) NULL DEFAULT NULL::character varying,
	"language" varchar(6) NOT NULL DEFAULT 'en-EN'::character varying,
	meta jsonb NOT NULL DEFAULT '{}'::json,
	group_description TEXT NULL,
	CONSTRAINT idx_cug_primary PRIMARY KEY (id),
	CONSTRAINT core_user_groups_fk FOREIGN KEY (group_type) REFERENCES public.code_list_usergroups_types(code)
);
CREATE UNIQUE INDEX core_user_groups_group_name_idx ON public.core_user_groups USING btree (group_name);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XAGRPGT','administration_user_group_get','SADMUSN','getUserGroup',NULL,'administration/users','administration','Permission to get user group','EXE','fa fa-save',1160,false,false,'{"notAvailable": ["free"]}');

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XADUGRP','administration_user_group_add','SADMUSN','addUserGroup',NULL,'administration/users','administration','Permission to add new user group','EXE','fa fa-save',1160,false,false,'{"notAvailable": ["free"]}');

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XAGRPUD','administration_user_group_update','SADMUSN','updateUserGroup',NULL,'administration/users','administration','Permission to update user group','EXE','fa fa-save',1160,false,false,'{"notAvailable": ["free"]}');

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XAGRPDL','administration_user_group_delete','SADMUSN','deleteUserGroup',NULL,'administration/users','administration','Permission to delete user group','EXE','fa fa-save',1160,false,false,'{"notAvailable": ["free"]}');

INSERT INTO public.core_assets (asset_type,asset_name,description,custom,asset_innerhtml,asset_parameters,asset_code,before_trigger,after_trigger,failure_rollback,exec_order,meta,role_id) VALUES
	 ('form','core_usergroups_form','Users Group form.',false,'<form id="core_users">
	<div class="row">
		<div class="form-group col-md-2">
			<label for="username">{core_users_form_username}</label>
			<input type="text" class="form-control" id="username" name="username" placeholder="Username">
		</div>
		<div class="form-group col-md-3">
			<label for="password">{core_users_form_password}</label>
			<input type="password" class="form-control" name="password" id="password" placeholder="Password">
		</div>
		<div class="form-group col-md-3">
			<label for="email">{core_users_form_email}</label>
			<input type="email" class="form-control" id="email" name="email" placeholder="Email">
			<input type="hidden" id="id" name="id">
		</div>
		<div class="form-group col-md-1">
			<label for="language">{core_users_form_language}</label>
			<select class="form-control" id="language" name="language" placeholder="language" data-list="api/v1/misc/translations/">
			</select>
		</div>		
		<div class="form-group col-md-3">
			<label for="organization">{core_users_form_organization}</label>
			<select data-null-first="true" class="form-control" id="organization" name="organization" data-list="api/v1/registry/registrylist/CLI">
			</select>
		</div>
		<div class="form-group col-md-3">
			<label for="department">{core_users_form_department}</label>
			<input data-null-first="true" class="form-control" id="department" type="text" name="meta[department]">
		</div>	
	</div>
	<div class="row">

	</div>
	<div class="row">
		<div class="form-group col-md-12">
			<label for="settings">{core_users_form_settings}</label>
			<div id="settings" data-name="settings" data-type="jsoneditor" class="jc-jsoneditor"></div>
		</div>		
	</div>	
</form>','{"form": [[{"id": "group_name", "cols": 6, "name": "group_name", "type": "text", "label": "Group Name", "autofocus": true, "mandatory": true, "relatedHidden": "id", "additionalClass": "form-control-sm"}, {"id": "email", "cols": 6, "name": "email", "type": "text", "label": "Email", "autofocus": true, "additionalClass": "form-control-sm"}], [{"id": "language", "cols": 3, "list": "api/v1/misc/translations/", "name": "language", "type": "dropdown", "label": "Language", "values": "list", "onchange": "jivaCoreOptions.unsavedData=true;", "mandatory": true, "additionalClass": "form-select-sm"}, {"id": "group_type", "cols": 3, "list": "/api/v1/misc/codelists/code_list_usergroups_types", "name": "group_type", "type": "dropdown", "label": "Type", "values": "description", "onchange": "jivaCoreOptions.unsavedData=true;setDutyTaskName();setDutyPrice();", "mandatory": true, "createForm": "admin_usergroups_codelist_form", "defaultValue": "ZZZ", "createEndpoint": "/api/v2/admin/codelists/code_list_usergroups_types", "additionalClass": "form-select-sm", "createdEntryFields": "description", "createEndpointMethod": "post"}, {"id": "group_description", "cols": 6, "name": "group_description", "type": "text", "label": "Description", "onchange": "generateDutyServiceCode(this)", "autofocus": true, "additionalClass": "form-control-sm"}]]}',NULL,NULL,NULL,0,NULL,NULL,NULL);


-- Auto-generated SQL script #202401151047
UPDATE public.core_assets
	SET asset_parameters='{
  "form": [
    [
      {
        "id": "username",
        "cols": 4,
        "name": "username",
        "type": "text",
        "label": "User",
        "autofocus": true,
        "mandatory": true,
        "relatedHidden": "id",
        "additionalClass": "form-control-sm"
      },
      {
        "id": "password",
        "cols": 4,
        "name": "password",
        "type": "text",
        "label": "Password",
        "autofocus": true,
        "additionalClass": "form-control-sm",
        "mandatory": true
      },
      {
        "id": "email",
        "cols": 4,
        "name": "email",
        "type": "text",
        "label": "Email",
        "autofocus": true,
        "additionalClass": "form-control-sm"
      }
    ],
    [
      {
        "id": "meta.primaryGroup",
        "key": "id",
        "cols": 5,
        "list": "api/v1/user/group/",
        "name": "meta[primaryGroup]",
        "type": "dropdown",
        "label": "Primary group",
        "values": "group_name",
        "onchange": "jivaCoreOptions.unsavedData=true;",
        "createForm": "core_usergroups_form",
        "createEndpoint": "/api/v1/user/group",
        "additionalClass": "form-select-sm",
        "createdEntryFields": "group_name",
        "createEndpointMethod": "post"
      },
      {
        "id": "organization",
        "cols": 5,
        "list": "api/v1/registry/registrylist/CLI",
        "name": "organization",
        "type": "dropdown",
        "label": "Organization",
        "values": "entity_name",
        "onchange": "jivaCoreOptions.unsavedData=true;",
        "additionalClass": "form-select-sm"
      },
      {
        "id": "language",
        "cols": 2,
        "list": "api/v1/misc/translations/",
        "name": "language",
        "type": "dropdown",
        "label": "Language",
        "values": "list",
        "onchange": "jivaCoreOptions.unsavedData=true;",
        "additionalClass": "form-select-sm",
        "mandatory": true
      }
    ]
  ]
}'::jsonb
	WHERE asset_name='core_users_form';
