Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isGridSelected(grid, title, message){
  2.     res = true;
  3.     if (!grid.getSelectionModel().hasSelection() ) {
  4.         Ext.Msg.show({
  5.            title: title,
  6.            msg: message,
  7.            buttons: Ext.Msg.OK,
  8.            icon: Ext.MessageBox.INFO
  9.         });
  10.         res = false;
  11.     };
  12.     return res;
  13. }
  14.  
  15. function selectValue(){
  16.     var id, displayText;
  17.  
  18.     var grid = Ext.getCmp('{{ component.grid.client_id}}');
  19.     if (!isGridSelected(grid, 'Выбор элемента', 'Выберите элемент из списка') ) {
  20.         return;
  21.     }
  22.    
  23.     {% if component.multi_select %}
  24.         var selections = grid.selModel.getSelections(),
  25.             len = selections.length,
  26.             ids = [],
  27.             displayTexts = [];
  28.         for (var i = 0; i < len; i += 1) {
  29.             ids.push(selections[i].id);
  30.             displayTexts.push(selections[i].get("{{ component.column_name_on_select }}"));
  31.         };
  32.         id = ids.join(',');
  33.         displayText = displayTexts.join(', ');
  34.     {% else %}
  35.         id = grid.getSelectionModel().getSelected().id;
  36.         displayText = grid.getSelectionModel().getSelected().get("{{ component.column_name_on_select }}");
  37.     {% endif %}
  38.  
  39.     var win = Ext.getCmp('{{ component.client_id }}');
  40.     {% if component.callback_url %}
  41.         Ext.Ajax.request({
  42.             url: "{{ component.callback_url }}"
  43.             , success: function(res,opt) {
  44.                 result = Ext.util.JSON.decode(res.responseText)
  45.                 if (!result.success){
  46.                     Ext.Msg.alert('Ошибка', result.message)
  47.                 }
  48.                 else {  
  49.                     win.fireEvent('closed_ok');
  50.                     win.close();
  51.                 }
  52.             }
  53.             ,params: Ext.applyIf({id: id}, {% if component.action_context %}{{component.action_context.json|safe}}{% else %}{}{% endif %})
  54.             ,failure: function(response, opts){
  55.                 uiAjaxFailMessage();
  56.             }
  57.         });
  58.     {% else %}
  59.         if (id!=undefined && displayText!=undefined){
  60.             win.fireEvent('select_value', id, displayText); // deprecated
  61.             win.fireEvent('closed_ok', id, displayText);
  62.         };
  63.         win.close();
  64.     {% endif %}
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement