cells: add action grid cell in card cell custom templates (#75908)
This commit is contained in:
parent
d9b5247f44
commit
cddd4635c7
|
@ -1015,7 +1015,7 @@ class WcsCardCell(CardMixin, CellBase):
|
|||
verbose_name = _('Card(s)')
|
||||
|
||||
class Media:
|
||||
js = ('js/combo.filter-cards.js', 'xstatic/select2.min.js')
|
||||
js = ('js/combo.filter-cards.js', 'xstatic/select2.min.js', 'js/combo.wcs-trigger-button.js')
|
||||
css = {'all': ('xstatic/select2.min.css', 'css/combo.filter-cards.css')}
|
||||
|
||||
def include_filters(self):
|
||||
|
@ -1171,7 +1171,7 @@ class WcsCardCell(CardMixin, CellBase):
|
|||
self.card_slug,
|
||||
self.card_custom_view,
|
||||
)
|
||||
api_url += '?include-fields=on&include-submission=on&include-workflow=on'
|
||||
api_url += '?include-fields=on&include-submission=on&include-workflow=on&include-actions=on'
|
||||
user = self.get_concerned_user(context)
|
||||
if self.only_for_user and user and not user.is_anonymous and user.get_name_id():
|
||||
api_url += '&filter-user-uuid=%s' % user.get_name_id()
|
||||
|
@ -1262,9 +1262,7 @@ class WcsCardCell(CardMixin, CellBase):
|
|||
card_custom_view,
|
||||
card_id,
|
||||
)
|
||||
api_url += (
|
||||
'?include-files-content=off&include-evolution=off&include-roles=off&include-workflow-data=off'
|
||||
)
|
||||
api_url += '?include-files-content=off&include-evolution=off&include-roles=off&include-workflow-data=off&include-actions=on'
|
||||
user = self.get_concerned_user(context)
|
||||
if only_for_user and user and not user.is_anonymous and user.get_name_id():
|
||||
api_url += '&filter-user-uuid=%s' % user.get_name_id()
|
||||
|
|
|
@ -41,6 +41,7 @@
|
|||
<option value="@info-field@">{% trans "Card information field" %}</option>
|
||||
<option value="@custom@">{% trans "Custom" %}</option>
|
||||
<option value="@link@">{% trans "Link" %}</option>
|
||||
<option value="@action@">{% trans "Action" %}</option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
|
@ -186,6 +187,47 @@
|
|||
</p>
|
||||
</div>
|
||||
|
||||
{# fields group for "content type == @action@" #}
|
||||
<div data-dynamic-display-child-of="entry_type" data-dynamic-display-value="@action@">
|
||||
<p>
|
||||
<label>
|
||||
{% trans "Label" %}
|
||||
<input name="action_label" />
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
{% trans "Action :" %}
|
||||
<select name="trigger_id">
|
||||
{% for id, action in card_schema.workflow.actions.items %}
|
||||
<option value="{{ id }}">{{ action.label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
{% trans "Ask confirmation " %}
|
||||
<input data-dynamic-display-parent="true" type="checkbox" value="true" name="action_ask_confirmation" style="resize: vertical;"></input>
|
||||
</label>
|
||||
</p>
|
||||
<p data-dynamic-display-child-of="action_ask_confirmation" data-dynamic-display-value-in=" True ">
|
||||
<label>
|
||||
{% trans "Confirmation text (Template)" %}
|
||||
<textarea name="action_confirmation_template" style="resize: vertical;"></textarea>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
{% trans "Unavailable action mode :" %}
|
||||
<select name="unavailable_action_mode">
|
||||
<option value="hide">{% trans "Hide action button" %}</option>
|
||||
<option value="disable">{% trans "Disable action button" %}</option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<p>
|
||||
<label>
|
||||
{% trans "Size" %}
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
<option value="@info-field@">{% trans "Card information field" %}</option>
|
||||
<option value="@custom@">{% trans "Custom" %}</option>
|
||||
<option value="@link@">{% trans "Link" %}</option>
|
||||
<option value="@action@">{% trans "Action" %}</option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
|
@ -151,6 +152,53 @@
|
|||
</label>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{# fields group for "content type == @action@" #}
|
||||
<div data-dynamic-display-child-of="entry_type" data-dynamic-display-value="@action@">
|
||||
<p>
|
||||
<label>
|
||||
{% trans "Header" %}
|
||||
<input name="action_header" />
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
{% trans "Label" %}
|
||||
<input name="action_label" />
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
{% trans "Action :" %}
|
||||
<select name="trigger_id">
|
||||
{% for id, action in card_schema.workflow.actions.items %}
|
||||
<option value="{{ id }}">{{ action.label }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
{% trans "Ask confirmation " %}
|
||||
<input data-dynamic-display-parent="true" type="checkbox" value="true" name="action_ask_confirmation" style="resize: vertical;"></input>
|
||||
</label>
|
||||
</p>
|
||||
<p data-dynamic-display-child-of="action_ask_confirmation" data-dynamic-display-value-in=" True ">
|
||||
<label>
|
||||
{% trans "Confirmation text (Template)" %}
|
||||
<textarea name="action_confirmation_template" style="resize: vertical;"></textarea>
|
||||
</label>
|
||||
</p>
|
||||
<p>
|
||||
<label>
|
||||
{% trans "Unavailable action mode :" %}
|
||||
<select name="unavailable_action_mode">
|
||||
<option value="hide">{% trans "Hide action button" %}</option>
|
||||
<option value="disable">{% trans "Disable action button" %}</option>
|
||||
</select>
|
||||
</label>
|
||||
</p>
|
||||
</div>
|
||||
</form>
|
||||
</template>
|
||||
<template class="as-table wcs-cards-cell--grid-cell-tpl">
|
||||
|
|
|
@ -429,11 +429,21 @@ $(function() {
|
|||
function prepare_dynamic_fields() {
|
||||
$('[data-dynamic-display-parent]').off('change input').on('change input', function() {
|
||||
var sel1 = '[data-dynamic-display-child-of="' + $(this).attr('name') + '"]';
|
||||
var sel2 = '[data-dynamic-display-value="' + $(this).val() + '"]';
|
||||
var sel3 = '[data-dynamic-display-value-in*=" ' + $(this).val() + ' "]';
|
||||
$(sel1).addClass('field-hidden').hide();
|
||||
$(sel1 + sel2).removeClass('field-hidden').show();
|
||||
$(sel1 + sel3).removeClass('field-hidden').show();
|
||||
|
||||
if(this.getAttribute('type') == 'checkbox') {
|
||||
if(this.checked) {
|
||||
$(sel1).removeClass('field-hidden').show();
|
||||
} else {
|
||||
$(sel1).addClass('field-hidden').hide();
|
||||
}
|
||||
}
|
||||
else {
|
||||
var sel2 = '[data-dynamic-display-value="' + $(this).val() + '"]';
|
||||
var sel3 = '[data-dynamic-display-value-in*=" ' + $(this).val() + ' "]';
|
||||
$(sel1).addClass('field-hidden').hide();
|
||||
$(sel1 + sel2).removeClass('field-hidden').show();
|
||||
$(sel1 + sel3).removeClass('field-hidden').show();
|
||||
}
|
||||
$(sel1).trigger('change');
|
||||
});
|
||||
$('[data-dynamic-display-child-of]').addClass('field-hidden').hide();
|
||||
|
@ -667,9 +677,12 @@ Card_cell_custom.prototype = {
|
|||
// set cell text
|
||||
let schema_field = this.field_with_varname(schema_cell.varname);
|
||||
let cell_text = "";
|
||||
if (schema_field || schema_cell.varname == '@custom@' || schema_cell.varname == '@link@') {
|
||||
if (schema_field || schema_cell.varname == '@custom@' || schema_cell.varname == '@link@' || schema_cell.varname == '@action@') {
|
||||
let cell_content = "";
|
||||
if (schema_cell.varname == '@custom@') {
|
||||
if (schema_cell.varname == '@action@') {
|
||||
cell_content += $(this.grid_cell_form).find('select[name="trigger_id"] option[value="' + schema_cell.trigger_id + '"]').text();
|
||||
cell_content += ' (' + gettext('Action Button') + ')';
|
||||
} else if (schema_cell.varname == '@custom@') {
|
||||
cell_content = (schema_cell.template || '') + ' (' + gettext('Custom') + ')';
|
||||
} else if (schema_cell.varname == '@link@') {
|
||||
cell_content = (schema_cell.template || '') + ': ';
|
||||
|
@ -695,7 +708,10 @@ Card_cell_custom.prototype = {
|
|||
cell_text += $('<span/>').addClass(schema_cell.display_mode).text(cell_content).html();
|
||||
cell_text += '<span class="cell-meta">';
|
||||
let cell_display_mode_label = '';
|
||||
if (schema_cell.varname == '@custom@') {
|
||||
if(schema_cell.varname == '@action@') {
|
||||
cell_display_mode_label = undefined
|
||||
}
|
||||
else if (schema_cell.varname == '@custom@') {
|
||||
cell_display_mode_label = $(this.grid_cell_form).find('select[name="custom_display_mode"] option[value="' + (schema_cell.display_mode || 'label') + '"]').text();
|
||||
} else if (schema_cell.varname == '@link@') {
|
||||
cell_display_mode_label = $(this.grid_cell_form).find('select[name="link_display_mode"] option[value="' + schema_cell.display_mode + '"]').text();
|
||||
|
@ -748,7 +764,16 @@ Card_cell_custom.prototype = {
|
|||
}
|
||||
|
||||
if (this.display_mode === 'card') {
|
||||
if (grid_cell.dataset.varname == '@custom@') {
|
||||
if (grid_cell.dataset.varname == '@action@') {
|
||||
this.grid_cell_form.elements.entry_type.value = '@action@';
|
||||
this.grid_cell_form.elements.action_label.value = grid_cell.dataset.action_label || '';
|
||||
this.grid_cell_form.elements.trigger_id.value = grid_cell.dataset.trigger_id || '';
|
||||
this.grid_cell_form.elements.action_ask_confirmation.value = 'true';
|
||||
this.grid_cell_form.elements.action_ask_confirmation.checked = grid_cell.dataset.action_ask_confirmation == 'true';
|
||||
this.grid_cell_form.elements.action_confirmation_template.value = grid_cell.dataset.action_confirmation_template || '';
|
||||
this.grid_cell_form.elements.unavailable_action_mode.value = grid_cell.dataset.unavailable_action_mode || '';
|
||||
}
|
||||
else if (grid_cell.dataset.varname == '@custom@') {
|
||||
this.grid_cell_form.elements.entry_type.value = '@custom@';
|
||||
this.grid_cell_form.elements.custom_template.value = grid_cell.dataset.template || '';
|
||||
this.grid_cell_form.elements.custom_display_mode.value = grid_cell.dataset.display_mode || 'label';
|
||||
|
@ -791,7 +816,17 @@ Card_cell_custom.prototype = {
|
|||
this.grid_cell_form.elements.cell_size.value = grid_cell.dataset.cell_size || '';
|
||||
|
||||
} else if (this.display_mode === 'table') {
|
||||
if (grid_cell.dataset.varname == '@custom@') {
|
||||
if (grid_cell.dataset.varname == '@action@') {
|
||||
this.grid_cell_form.elements.entry_type.value = '@action@';
|
||||
this.grid_cell_form.elements.action_header.value = grid_cell.dataset.header || '';
|
||||
this.grid_cell_form.elements.action_label.value = grid_cell.dataset.action_label || '';
|
||||
this.grid_cell_form.elements.trigger_id.value = grid_cell.dataset.trigger_id || '';
|
||||
this.grid_cell_form.elements.action_ask_confirmation.value = 'true';
|
||||
this.grid_cell_form.elements.action_ask_confirmation.checked = grid_cell.dataset.action_ask_confirmation == 'true';
|
||||
this.grid_cell_form.elements.action_confirmation_template.value = grid_cell.dataset.action_confirmation_template || '';
|
||||
this.grid_cell_form.elements.unavailable_action_mode.value = grid_cell.dataset.unavailable_action_mode || '';
|
||||
}
|
||||
else if (grid_cell.dataset.varname == '@custom@') {
|
||||
this.grid_cell_form.elements.entry_type.value = '@custom@';
|
||||
if (this.display_mode == 'table') {
|
||||
this.grid_cell_form.elements.custom_header.value = grid_cell.dataset.header || '';
|
||||
|
@ -862,7 +897,15 @@ Card_cell_custom.prototype = {
|
|||
for (var data in schema_cell) delete schema_cell[data];
|
||||
|
||||
if (this.display_mode == 'card') {
|
||||
if (form_datas.entry_type == '@custom@') {
|
||||
if (form_datas.entry_type == '@action@') {
|
||||
schema_cell.varname = '@action@';
|
||||
schema_cell.trigger_id = form_datas.trigger_id;
|
||||
schema_cell.action_label = form_datas.action_label;
|
||||
schema_cell.action_ask_confirmation = form_datas.action_ask_confirmation == 'true';
|
||||
schema_cell.action_confirmation_template = form_datas.action_confirmation_template;
|
||||
schema_cell.unavailable_action_mode = form_datas.unavailable_action_mode;
|
||||
}
|
||||
else if (form_datas.entry_type == '@custom@') {
|
||||
schema_cell.varname = '@custom@';
|
||||
schema_cell.display_mode = form_datas.custom_display_mode;
|
||||
schema_cell.template = form_datas.custom_template;
|
||||
|
@ -909,7 +952,16 @@ Card_cell_custom.prototype = {
|
|||
schema_cell.cell_size = form_datas.cell_size;
|
||||
|
||||
} else if (this.display_mode == 'table') {
|
||||
if (form_datas.entry_type == '@custom@') {
|
||||
if (form_datas.entry_type == '@action@') {
|
||||
schema_cell.varname = '@action@';
|
||||
schema_cell.header = form_datas.action_header;
|
||||
schema_cell.trigger_id = form_datas.trigger_id;
|
||||
schema_cell.action_label = form_datas.action_label;
|
||||
schema_cell.action_ask_confirmation = form_datas.action_ask_confirmation == 'true';
|
||||
schema_cell.action_confirmation_template = form_datas.action_confirmation_template;
|
||||
schema_cell.unavailable_action_mode = form_datas.unavailable_action_mode;
|
||||
}
|
||||
else if (form_datas.entry_type == '@custom@') {
|
||||
schema_cell.varname = '@custom@';
|
||||
schema_cell.header = form_datas.custom_header;
|
||||
schema_cell.template = form_datas.custom_template;
|
||||
|
|
Loading…
Reference in New Issue