MIGX icon indicating copy to clipboard operation
MIGX copied to clipboard

Custom renderSwitchStatusOptions icons dissapear, when saving the formtab

Open DmitryFX opened this issue 2 years ago • 1 comments

https://user-images.githubusercontent.com/17983905/184842176-27ac55ed-6971-4d5a-8b90-05c7fabc43ca.mp4

image

UPD. It seems, that renderSwitchStatusOptions @ migx\configs\grid\grid.renderer.inc.php is called twice when formtab save is hit. The first call has correct data (has render options), the second - not. image

And during the page reload renderSwitchStatusOptions is called maaaaaaaaany times for the single row migx. Why?

image

Config. Not really makes sense, as I've tried a lot of variations of default values and so on.. { "formtabs":[ { "MIGX_id":1, "caption":"\u0424\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u0438", "print_before_tabs":"0", "fields":[ { "MIGX_id":1, "field":"image", "caption":"\u0424\u043e\u0442\u043e", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"image", "validation":"", "configs":"", "restrictive_condition":"", "display":"", "sourceFrom":"migx", "sources":"", "inputOptionValues":"", "default":"", "useDefaultIfEmpty":"0", "pos":1 }, { "MIGX_id":44, "field":"text", "caption":"\u0422\u0435\u043a\u0441\u0442", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"richtext", "validation":"", "configs":"", "restrictive_condition":"", "display":"", "sourceFrom":"config", "sources":"", "inputOptionValues":"", "default":"", "useDefaultIfEmpty":"0", "pos":2 }, { "MIGX_id":46, "field":"visible_in_slider", "caption":"\u0412\u0438\u0434\u0435\u043d \u0432 \u0441\u043b\u0430\u0439\u0434\u0435\u0440\u0435", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"", "validation":"", "configs":"", "restrictive_condition":"", "display":"", "sourceFrom":"config", "sources":"", "inputOptionValues":"", "default":"", "useDefaultIfEmpty":"0", "pos":3 }, { "MIGX_id":45, "field":"visible_on_page", "caption":"\u0412\u0438\u0434\u0435\u043d \u0432 \u043e\u043a\u043d\u0435", "description":"", "description_is_code":"0", "inputTV":"", "inputTVtype":"checkbox", "validation":"", "configs":"", "restrictive_condition":"", "display":"", "sourceFrom":"config", "sources":"", "inputOptionValues":1, "default":"0", "useDefaultIfEmpty":1, "pos":4 } ], "pos":1 } ], "contextmenus":"edit_migx||remove_migx_and_image", "actionbuttons":"loadfromsource||uploadfiles", "columnbuttons":"remove_migx_and_image", "filters":"", "extended":{ "migx_add":"\u0417\u0430\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0444\u043e\u0442\u043e", "disable_add_item":1, "add_items_directly":1, "formcaption":"\u0424\u043e\u0442\u043e \u043a\u043e\u043b\u043b\u0435\u043a\u0446\u0438\u044f", "update_win_title":"", "win_id":"migx_photo_uploads_ext_win_id", "maxRecords":"", "addNewItemAt":"bottom", "media_source_id":"", "multiple_formtabs":"", "multiple_formtabs_label":"", "multiple_formtabs_field":"", "multiple_formtabs_optionstext":"", "multiple_formtabs_optionsvalue":"", "actionbuttonsperrow":4, "winbuttonslist":"", "extrahandlers":"this.selectSelectorOption||this.addItem||this.addNewItem||this.uploadImages||this.update||this.handleColumnSwitch||this.uploadFiles||this.uploadSuccess", "filtersperrow":4, "packageName":"", "classname":"", "task":"", "getlistsort":"", "getlistsortdir":"", "sortconfig":"", "gridpagesize":"", "use_custom_prefix":"0", "prefix":"", "grid":"", "gridload_mode":1, "check_resid":1, "check_resid_TV":"", "join_alias":"", "has_jointable":"yes", "getlistwhere":"", "joins":"", "hooksnippets":"", "cmpmaincaption":"", "cmptabcaption":"", "cmptabdescription":"", "cmptabcontroller":"", "winbuttons":"", "onsubmitsuccess":"", "submitparams":"" }, "permissions":{ "apiaccess":"", "view":"", "list":"", "save":"", "create":"", "remove":"", "delete":"", "publish":"", "unpublish":"", "viewdeleted":"", "viewunpublished":"" }, "fieldpermissions":"", "columns":[ { "MIGX_id":1, "header":"\u0424\u043e\u0442\u043e\u0433\u0440\u0430\u0444\u0438\u044f", "dataIndex":"image", "width":2, "sortable":"false", "show_in_grid":1, "customrenderer":"", "renderer":"this.renderImage", "clickaction":"", "selectorconfig":"", "renderchunktpl":"", "renderoptions":"", "editor":"" }, { "MIGX_id":4, "header":"\u041f\u043e\u0434\u043f\u0438\u0441\u044c", "dataIndex":"text", "width":4, "sortable":"false", "show_in_grid":1, "customrenderer":"", "renderer":"", "clickaction":"", "selectorconfig":"", "renderchunktpl":"", "renderoptions":"", "editor":"this.textEditor" }, { "MIGX_id":2, "header":"\u041d\u0430 \u0433\u043b\u0430\u0432\u043d\u043e\u0439 (1 - 5 \u0448\u0442.)", "dataIndex":"visible_in_slider", "width":1, "sortable":true, "show_in_grid":1, "customrenderer":"", "renderer":"this.renderSwitchStatusOptions", "clickaction":"switchOption", "selectorconfig":"", "renderchunktpl":"", "renderoptions":[ { "MIGX_id":3, "name":"0", "use_as_fallback":1, "value":"0", "clickaction":"switchOption", "handler":"", "image":"assets/img/icons/no.png" }, { "MIGX_id":1, "name":1, "use_as_fallback":"", "value":1, "clickaction":"switchOption", "handler":"", "image":"assets/img/icons/yes.png" }, { "MIGX_id":6, "name":"0", "use_as_fallback":"", "value":"0", "clickaction":"switchOption", "handler":"", "image":"assets/img/icons/no.png" } ], "editor":"" }, { "MIGX_id":3, "header":"\u0412 \u043e\u043a\u043d\u0435", "dataIndex":"visible_on_page", "width":1, "sortable":true, "show_in_grid":1, "customrenderer":"", "renderer":"this.renderSwitchStatusOptions", "clickaction":"switchOption", "selectorconfig":"", "renderchunktpl":"", "renderoptions":[ { "MIGX_id":4, "name":"0", "use_as_fallback":1, "value":"0", "clickaction":"switchOption", "handler":"", "image":"assets/img/icons/no.png" }, { "MIGX_id":6, "name":1, "use_as_fallback":"", "value":1, "clickaction":"switchOption", "handler":"", "image":"assets/img/icons/yes.png" }, { "MIGX_id":7, "name":"0", "use_as_fallback":"", "value":"0", "clickaction":"switchOption", "handler":"", "image":"assets/img/icons/no.png" } ], "editor":"" } ], "category":"" }

DmitryFX avatar Aug 16 '22 09:08 DmitryFX

I don't think you can make this work with renderSwitchStatusOptions. The problem is, that the render information (what picture to show etc.) is generated in PHP and stored in an extra field with the ending _ro (e.g. visible_on_page_ro). When you click "Save" in the update-window this information is lost.

https://github.com/Bruno17/MIGX/blob/b14c5abdb5503095b18975b391ef2615811c63aa/core/components/migx/elements/tv/migx.tpl#L198

You'd have to make an AJAX-call to get the current render information.


The easiest solution is probably to code a custom renderer with hard-coded render options.

  • Create a file grid.config.inc.php in core/components/somepackagename/migxconfigs/grid.
  • Add code for your custom renderer and handler function to this file. Something like this may work:
<?php
$my_img = '<a href="#" ><img class="controlBtn {3} {4} {5}" src="'.$base_url.'{0}" alt="{1}" title="{2}"></a>';
$renderer['this.myRenderSwitchStatusOptions'] = "
myRenderSwitchStatusOptions : function(val, md, rec, row, col, s) {
    var column = this.getColumnModel().getColumnAt(col);
    var renderImage, altText, handler, classname;
    if (val == '1'){
        renderImage = 'assets/img/icons/yes.png';
        altText = 'yes';
    } else {
        renderImage = 'assets/img/icons/no.png';
        altText = 'no';
    }
    handler = 'this.myHandleColumnSwitch';
    classname = '';
    return String.format('{$my_img}', renderImage, altText, altText, classname, handler, column.dataIndex);
}
";

$gridfunctions['this.myHandleColumnSwitch'] = "
myHandleColumnSwitch: function(n,e,col) {   
    this.selected_records = this.getSelectionModel().getSelections();
    var old_val = this.selected_records[0].get(col);
    var new_val;
    if (old_val == '1'){
        new_val = '';
    } else {
        new_val = '1';
    }
    this.updateSelected({dataIndex: col}, new_val);
}	
";
?>
  • In your config in the tab "MIGXdb-Settings" set the field "Package" to somepackagename.
  • In the tab "Columns" select your custom renderer ("this.myRenderSwitchStatusOptions") from the list.
  • In the tab "Handlers" check the checkbox for the custom handler "this.myHandleColumnSwitch".

halftrainedharry avatar Aug 17 '22 14:08 halftrainedharry