Advertisement
Guest User

Untitled

a guest
Jan 20th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 36.42 KB | None | 0 0
  1. <%=
  2.   ext_remote_component_config do |js|
  3.     js.js_return Ext.create({
  4.                                 xtype: 'container',
  5.                                 layout: 'border',
  6.                                 id: ext_cmp_id_for('news_container'),
  7.                                 items: [
  8.                                         {
  9.                                                 xtype: 'remotepanel',
  10.                                                 id: ext_cmp_id_for('sko_window'),
  11.                                                 title: '',
  12.                                                 modal: true,
  13.                                                 border: false,
  14.                                                 layout: 'fit',
  15.                                                 closable: true,
  16.                                                 closeAction: 'hide',
  17.                                                 dockable: true,
  18.                                                 forceReload: true,
  19.                                                 remoteCfg: {
  20.                                                         removeAllOnLoad: true,
  21.                                                         maskContainer: true,
  22.                                                         method: 'GET'
  23.                                                 },
  24.                                                 wndOptions: {
  25.                                                         onEsc: 'Ext.emptyFn',
  26.                                                         maximizable: true,
  27.                                                         maximized: true,
  28.                                                         alwaysOnTop: true
  29.                                                 }
  30.  
  31.                                         },
  32.  
  33.                                 {
  34.                                         :xtype => 'railsform',
  35.                                         :region => 'center',
  36.                                         :edit => params[:edit],
  37.  
  38.                                         :no_edit => !@news_post.new_record? && !(current_user.admin? || @news_post.author?(current_user)),
  39.                                         :show_delete => current_user.admin?,
  40.  
  41.  
  42.                                         :url_prefix => '/news_posts',
  43.                                         :rails_obj_id => params[:id],
  44.                                         :baseParams => {:authenticity_token => form_authenticity_token},
  45.                                         :ext_cfg => {:fileUpload => true},
  46.  
  47.  
  48.  
  49.                                         :listeners => {
  50.                                             :actioncomplete => <<-EOJS.to_js,
  51.                               function(f, a){
  52.                                 if (a.type == 'load') {
  53.                                         if (a.result.data['news_post[is_sku_file]']) {
  54.                                             Ext.getCmp('#{ext_cmp_id_for('sku_file')}').show();
  55.                                             Ext.getCmp('#{ext_cmp_id_for('status_ids')}').hide();
  56.                                             Ext.getCmp('#{ext_cmp_id_for('voc_region_ids')}').hide();
  57.                                             Ext.getCmp('#{ext_cmp_id_for('voc_property_type_ids')}').hide();
  58.                                         }else{
  59.                                             Ext.getCmp('#{ext_cmp_id_for('sku_file')}').hide();
  60.                                             Ext.getCmp('#{ext_cmp_id_for('status_ids')}').show();
  61.                                             Ext.getCmp('#{ext_cmp_id_for('voc_region_ids')}').show();
  62.                                             Ext.getCmp('#{ext_cmp_id_for('voc_property_type_ids')}').show();
  63.                                         }
  64.                                 }
  65.  
  66.                               }
  67.                                             EOJS
  68.  
  69.                                         },
  70.  
  71.  
  72.  
  73.  
  74.  
  75.                                         :rightButtons => [
  76.                                             {
  77.                                                 :xtype => 'button',
  78.                                                 :text => 'Отправить рассылку',
  79.                                                 :off => @news_post.is_sent? || @news_post.new_record? || !(current_user.admin? || @news_post.author?(current_user)),
  80.                                                 :qtip => 'Отправить рассылку',
  81.                                                 #:iconCls => 'icon-application-get',
  82.                                                 :handler => <<-EOJS.to_js
  83.                               function(){
  84.  
  85.                                     Ext.Ajax.request({
  86.                                       url : '/news_posts/#{@news_post.id}/send_email',
  87.                                       method : 'POST',
  88.                                       params : {
  89.                                           _method : 'POST',
  90.                                           authenticity_token : '#{form_authenticity_token}'
  91.                                     },
  92.                                     success : function(response) {
  93.                                         var result = Ext.decode(response.responseText);
  94.                                         if (result.success) {
  95.                                             Ext.getCmp('#{ext_cmp_id_for('news_container')}').reloadParentRemote();
  96.                                         } else {
  97.                                             Ext.MessageBox.alert("Ошибка", result.errors.base);
  98.                                         }
  99.                                     }
  100.                                   });
  101.  
  102.                               }
  103.                                                 EOJS
  104.                                             },
  105.                                         ],
  106.                                         :items => [
  107.                                             {
  108.                                                 :name => 'news_post[dt]',
  109.                                                 :xtype => 'xdatefield',
  110.                                                 :fieldLabel => 'Дата'
  111.                                             },
  112.  
  113.                                             {
  114.                                                 :name => 'news_post[label]',
  115.                                                 :xtype => 'textfield',
  116.                                                 :fieldLabel => 'Заголовок',
  117.                                                 :width => 155 + 350
  118.                                             },
  119.  
  120.                                             {
  121.                                                 :name => 'news_post[body]',
  122.                                                 :xtype => 'textarea',
  123.                                                 :fieldLabel => 'Текст новости',
  124.                                                 :maxLength => 10000,
  125.                                                 :width => 155 + 350,
  126.                                                 id: ext_cmp_id_for('body_id'),
  127.                                             },
  128.  
  129.                                             {
  130.                                                     :xtype => 'displayfield',
  131.                                                     :fieldLabel => 'Вкладки',
  132.                                                     :width => 155 + 350,
  133.                                                     :value => NewsPostSkuBlankTab.by_sku(current_user.try(:sku_id)).by_news_post(@news_post.try(:id)).first.try(:tabs),
  134.                                                     :off => !@news_post.try(:is_filling_info) || !current_user.sku?
  135.                                             },
  136.  
  137.                                             {
  138.                                                 :xtype => 'fileuploadfield',
  139.                                                 :emptyText => 'Выберите файл',
  140.                                                 :fieldLabel => 'Файл',
  141.                                                 :name => 'news_post[news_file]',
  142.                                                 :buttonText => '',
  143.                                                 :buttonConfig => {
  144.                                                     :iconCls => 'icon-folder'
  145.                                                 }
  146.  
  147.                                             },
  148.                                             {
  149.                                                 xtype: 'railsmulticombo',
  150.                                                 fieldLabel: 'Роли',
  151.                                                 off: !(current_user.admin? || current_user.hq?),
  152.                                                 values: roles_voc_with_news_stats(Role.news_roles_for(current_user), @news_post),
  153.                                                 name: 'news_post[role_ids]',
  154.                                                 listeners: {
  155.                                                     change: "function() {
  156.                                                                  if (Ext.Array.indexOf(this.getValue(), 4) != -1) {
  157.                                                                      Ext.getCmp('#{ext_cmp_id_for('nko_settings')}').show();
  158.                                                                  } else {
  159.                                                                      Ext.getCmp('#{ext_cmp_id_for('nko_settings')}').hide();
  160.                                                                  }
  161.                                                                  if(this.getValue().length == 1 && Ext.Array.indexOf(this.getValue(), 4) != -1){
  162.                                                                     Ext.getCmp('#{ext_cmp_id_for('is_filling_info_id')}').show();
  163.                                                                  }else{
  164.                                                                     Ext.getCmp('#{ext_cmp_id_for('is_filling_info_id')}').hide();
  165.                                                                     Ext.getCmp('#{ext_cmp_id_for('is_filling_info_id')}').setValue(false);
  166.                                                                  }
  167.                                                            }".to_js
  168.                                                 }
  169.                                             },
  170.                                             {
  171.                                                 fieldLabel: 'Новость создана',
  172.                                                 off: @news_post.new_record? || @news_post.user.blank? || @news_post.user.admin? || @news_post.user.hq?,
  173.                                                 xtype: 'displayfield',
  174.                                                 name: 'news_post[created_by]',
  175.                                                 width: 155 + 500,
  176.                                             },
  177.                                             {
  178.                                                 xtype: 'fieldset',
  179.                                                 title: 'Настройка параметров отображения новости для пользователей санаторно-курортных организаций (роль Оператор СКО)',
  180.                                                 id: ext_cmp_id_for('nko_settings'),
  181.                                                 hidden: true,
  182.                                                 items: [
  183.  
  184.                                                     {
  185.                                                         :xtype => 'xcheckbox',
  186.                                                         :name => 'news_post[is_sku_file]',
  187.                                                         :fieldLabel => 'Список из файла',
  188.                                                         :id => ext_cmp_id_for('is_sku_file'),
  189.                                                         :handler  => <<-EOJS.to_js
  190.                                                                 function() {
  191.                                                                     if(this.checked) {
  192.                                                                         Ext.getCmp('#{ext_cmp_id_for('sku_file')}').show();
  193.                                                                         Ext.getCmp('#{ext_cmp_id_for('status_ids')}').hide();
  194.                                                                         Ext.getCmp('#{ext_cmp_id_for('voc_region_ids')}').hide();
  195.                                                                         Ext.getCmp('#{ext_cmp_id_for('voc_property_type_ids')}').hide();
  196.                                                                     }else{
  197.                                                                         Ext.getCmp('#{ext_cmp_id_for('sku_file')}').hide();
  198.                                                                         Ext.getCmp('#{ext_cmp_id_for('status_ids')}').show();
  199.                                                                         Ext.getCmp('#{ext_cmp_id_for('voc_region_ids')}').show();
  200.                                                                         Ext.getCmp('#{ext_cmp_id_for('voc_property_type_ids')}').show();
  201.                                                                     }
  202.                                                                 }
  203.                                                         EOJS
  204.                                                     },
  205.                                                     {
  206.                                                         :xtype => 'fileuploadfield',
  207.                                                         :emptyText => 'Выберите файл',
  208.                                                         :fieldLabel => 'Список СКО',
  209.                                                         :id => ext_cmp_id_for('sku_file'),
  210.                                                         :name => 'news_post[sku_file]',
  211.                                                         :buttonText => '',
  212.                                                         :buttonConfig => {
  213.                                                             :iconCls => 'icon-folder'
  214.                                                         }
  215.                                                     },
  216.                                                     {
  217.                                                         xtype: 'railsmulticombo',
  218.                                                         fieldLabel: 'Статусы',
  219.                                                         id: ext_cmp_id_for('status_ids'),
  220.                                                         values: [
  221.                                                             {id: -1, label: 'Проект'},
  222.                                                             {id: 0, label: 'Опубликовано'},
  223.                                                             {id: 1, label: 'Согласовано'},
  224.                                                             {id: 2, label: 'Утверждено'},
  225.                                                         ],
  226.                                                         name: 'news_post[status_ids]',
  227.                                                     },
  228.                                                     {
  229.                                                             :xtype => 'xcheckbox',
  230.                                                             :name => 'news_post[is_filling_info]',
  231.                                                             :fieldLabel => 'Заполненность',
  232.                                                             :id => ext_cmp_id_for('is_filling_info_id'),
  233.                                                             :handler  => <<-EOJS.to_js
  234.                                                                 function() {
  235.                                                                     if(this.checked) {
  236.                                                                         Ext.getCmp('#{ext_cmp_id_for('body_id')}').setValue('Уважаемые коллеги, просьба заполнить(дозаполнить) следующие вкладки:');
  237.                                                                     }else{
  238.                                                                         Ext.getCmp('#{ext_cmp_id_for('body_id')}').setValue('');
  239.                                                                     }
  240.                                                                 }
  241.                                                             EOJS
  242.                                                     },
  243.                                                     {
  244.                                                         xtype: 'itemselector',
  245.                                                         name: 'news_post[voc_region_ids]',
  246.                                                         fieldLabel: 'Регионы',
  247.                                                         id: ext_cmp_id_for('voc_region_ids'),
  248.                                                         #anchor: '100%',
  249.                                                         height: 200,
  250.                                                         store: Ext.create('Ext.data.Store', {
  251.                                                             fields: ['id', 'label'],
  252.                                                             data: VocRegion.order(:code).as_json(only: [:id, :label])
  253.                                                         }),
  254.                                                         displayField: 'label',
  255.                                                         valueField: 'id',
  256.                                                         fromTitle: 'Доступно',
  257.                                                         toTitle: 'Выбрано',
  258.                                                         buttons: ['addall', 'add', 'remove', 'removeall'],
  259.                                                         msgTarget: 'under'
  260.                                                     },
  261.                                                     {
  262.                                                         xtype: 'checktreefield',
  263.                                                         name: 'news_post[voc_property_type_ids]',
  264.                                                         id: ext_cmp_id_for('voc_property_type_ids'),
  265.                                                         height: 200,
  266.                                                         #padding: '5 0 5 0',
  267.                                                         fieldLabel: 'Формы собственности',
  268.                                                         store: {
  269.                                                             xtype: 'store',
  270.                                                             fields: ['id', 'text', {
  271.                                                                 name: 'checked',
  272.                                                                 defaultValue: false
  273.                                                             }],
  274.                                                             data: [{id: -1, text: '[Не указано]', leaf: true}] + VocPropertyType.tree_data(VocPropertyType.roots)
  275.                                                         },
  276.  
  277.                                                         toggleChildren: true,
  278.                                                         msgTarget: 'under'
  279.                                                     },
  280.                                                 ],
  281.                                             },
  282.  
  283.                                         ]
  284.                                     },
  285.                                     {
  286.                                         :xtype => 'railsgrid',
  287.                                         :off => @news_post.new_record?,
  288.                                         :region => 'south',
  289.                                         :split => true,
  290.                                         #:height => '50',
  291.                                         :flex => 1,
  292.                                         :url => @news_post.new_record? ? '/' : comments_news_post_path(@news_post),
  293.                                         :url_prefix => @news_post.new_record? ? '/' : comments_news_post_path(@news_post),
  294.                                         :root => 'comments',
  295.                                         :title => 'Вопросы',
  296.  
  297.                                         :no_add_button => true,
  298.                                         :no_view_button => true,
  299.                                         :no_search => true,
  300.  
  301.                                         #:no_bbar => true,
  302.  
  303.                                         :totalProperty => 'res',
  304.                                         :request_forgery_protection_token => request_forgery_protection_token,
  305.                                         :form_authenticity_token => form_authenticity_token,
  306.                                         :ext_cfg => {
  307.                                             viewConfig: {
  308.                                                 getRowClass: "function(record) {
  309.                                return record.get('no_answer') ? 'x-grid3-row-highlight-pink' : '';
  310.                              }".to_js
  311.                                             }
  312.                                         },
  313.  
  314.  
  315.  
  316.                                         :fields => [
  317.                                             {
  318.                                                 :name => :label,
  319.                                                 :label => 'Тема'
  320.                                             },
  321.                                             {
  322.                                                 :name => :user_label,
  323.                                                 :label => 'Пользователь'
  324.                                             },
  325.                                             {
  326.                                                     :name => :org_label,
  327.                                                     :label => 'Организация'
  328.                                             },
  329.                                             {
  330.                                                 :name => :dt,
  331.                                                 :label => 'Дата',
  332.                                                 :type => 'datetime'
  333.                                             },
  334.                                         ],
  335.                                         :row_expander => {
  336.                                             :rowBodyTpl => Ext::XTemplate.new(<<-EOTPL)
  337.                                             <p>{body}</p>
  338.  
  339.  
  340.                                             <tpl if="Ext.isArray(answers)">
  341.                                                 <p><b>Ответы</b></p>
  342.                                                 <table class="row-inner-table">
  343.                                                         <tpl for="answers">
  344.                                                         <tr>
  345.                                                             <td>{label}</td>
  346.                                                             <td>{user_label}</td>
  347.                                                             <td>{org_label}</td>
  348.                                                             <td>{dt:date("m.d.Y H:i")}</td>
  349.                                                         </tr>
  350.                                                         <tr>
  351.                                                             <td colspan=3>{body}</td>
  352.                                                         </tr>
  353.                                                         </tpl>
  354.                                                 </table>
  355.                                             </tpl>
  356.  
  357.                                             EOTPL
  358.                                         },
  359.                                         :tbar_left => current_user.no_edit ? [] : [
  360.                                             {
  361.                                                 xtype: 'button',
  362.                                                 iconCls: 'icon-add',
  363.                                                 text: 'Добавить вопрос',
  364.                                                 handler: <<-EJS.to_js
  365.                                                 function() {
  366.                                                       var grid = this.findParentByType('railsgrid');
  367.  
  368.  
  369.                                                       Ext.getCmp('#{ext_cmp_id_for('comment_panel')}').show();
  370.                                                       Ext.getCmp('#{ext_cmp_id_for('comment_label')}').setValue('');
  371.                                                       Ext.getCmp('#{ext_cmp_id_for('comment_body')}').setValue('');
  372.                                                       Ext.getCmp('#{ext_cmp_id_for('comment_submit')}').setHandler(function(){
  373.                                                           var self = this;
  374.                                                           self.disable();
  375.                                                           Ext.Ajax.request({
  376.                                                               url : '#{@news_post.new_record? ? '' : comment_news_post_path(@news_post, :ext_json)}',
  377.                                                               method : 'POST',
  378.                                                               params : {
  379.                                                                   _method : 'POST',
  380.                                                                   label : Ext.getCmp('#{ext_cmp_id_for('comment_label')}').getValue(),
  381.                                                                   body : Ext.getCmp('#{ext_cmp_id_for('comment_body')}').getValue(),
  382.                                                                   authenticity_token : '#{form_authenticity_token}'
  383.                                                               },
  384.                                                               success : function(response) {
  385.                                                                   self.enable();
  386.                                                                   var result = Ext.decode(response.responseText);
  387.                                                                   if (result.success) {
  388.                                                                       Ext.getCmp('#{ext_cmp_id_for('comment_panel')}').hide();
  389.                                                                       grid.getStore().reload();
  390.                                                                   } else if (result.errors) {
  391.                                                                       if (result.errors['news_comment[label]'])
  392.                                                                           Ext.getCmp('#{ext_cmp_id_for('comment_label')}').markInvalid(result.errors['news_comment[label]']);
  393.                                                                       if (result.errors['news_comment[body]'])
  394.                                                                           Ext.getCmp('#{ext_cmp_id_for('comment_body')}').markInvalid(result.errors['news_comment[body]']);
  395.                                                                   } else {
  396.                                                                       Ext.MessageBox.alert("Ошибка", 'Нет ответа от сервера');
  397.                                                                   }
  398.                                                               }
  399.                                                           });
  400.                                                       });
  401.                                                  }
  402.                                                 EJS
  403.                                             }
  404.                                         ],
  405.                                         :row_actions => current_user.no_edit ? [] : [
  406.                                             {
  407.                                                 :iconCls => 'icon-form-edit',
  408.                                                 :tooltip => 'Ответить',
  409.                                                 # :isDisabled => 'function(view, rowIndex, colIndex, item, record) {
  410.                                                 #       return !!record.get("excluded_at")
  411.                                                 #     }'.to_js,
  412.                                                 :handler => <<-EJS.to_js
  413.                                                 function(view, rowIndex, colIndex, item, e, record) {
  414.                                                       var grid = view.up('railsgrid,railstreegrid');
  415.  
  416.  
  417.                                                       Ext.getCmp('#{ext_cmp_id_for('comment_panel')}').show();
  418.                                                       Ext.getCmp('#{ext_cmp_id_for('comment_label')}').setValue('');
  419.                                                       Ext.getCmp('#{ext_cmp_id_for('comment_body')}').setValue('');
  420.                                                       Ext.getCmp('#{ext_cmp_id_for('comment_submit')}').setHandler(function(){
  421.                                                           var self = this;
  422.                                                           self.disable();
  423.                                                           Ext.Ajax.request({
  424.                                                               url : '#{@news_post.new_record? ? '' : comment_news_post_path(@news_post, :ext_json)}',
  425.                                                               method : 'POST',
  426.                                                               params : {
  427.                                                                   _method : 'POST',
  428.                                                                   parent_id: record.get('id'),
  429.                                                                   label : Ext.getCmp('#{ext_cmp_id_for('comment_label')}').getValue(),
  430.                                                                   body : Ext.getCmp('#{ext_cmp_id_for('comment_body')}').getValue(),
  431.                                                                   authenticity_token : '#{form_authenticity_token}'
  432.                                                               },
  433.                                                               success : function(response) {
  434.                                                                   self.enable();
  435.                                                                   var result = Ext.decode(response.responseText);
  436.                                                                   if (result.success) {
  437.                                                                       Ext.getCmp('#{ext_cmp_id_for('comment_panel')}').hide();
  438.                                                                       grid.getStore().reload();
  439.                                                                   } else if (result.errors) {
  440.                                                                       if (result.errors['news_comment[label]'])
  441.                                                                           Ext.getCmp('#{ext_cmp_id_for('comment_label')}').markInvalid(result.errors['news_comment[label]']);
  442.                                                                       if (result.errors['news_comment[body]'])
  443.                                                                           Ext.getCmp('#{ext_cmp_id_for('comment_body')}').markInvalid(result.errors['news_comment[body]']);
  444.                                                                   } else {
  445.                                                                       Ext.MessageBox.alert("Ошибка", 'Нет ответа от сервера');
  446.                                                                   }
  447.                                                               }
  448.                                                           });
  449.                                                       });
  450.                                                  }
  451.                                                 EJS
  452.                                             },
  453.                                             {
  454.                                                 :iconCls => 'icon-view',
  455.                                                 :tooltip => 'Открыть СКО',
  456.                                                 :handler => <<-EOJS.to_js,
  457.                                                     function() {
  458.                                                           var win = Ext.getCmp('#{ext_cmp_id_for('sko_window')}');
  459.                                                           console.log(win);
  460.                                                           win.show();
  461.                                                           win.reloadRailsCmp('#{ sku_path(3203) }');
  462.                                                     }
  463.                                                 EOJS
  464.                                             }
  465.                                         ]
  466.                                     },
  467.                                     {
  468.                                         xtype: 'window',
  469.                                         width: 400,
  470.                                         height: 200,
  471.                                         title: '',
  472.                                         noDefaultButtons: true,
  473.                                         id: ext_cmp_id_for('comment_panel'),
  474.                                         layout: 'fit',
  475.                                         modal: true,
  476.                                         closeAction: 'hide',
  477.                                         items: {
  478.                                             xtype: 'form',
  479.                                             bodyPadding: 5,
  480.                                             border: false,
  481.                                             layout: 'anchor',
  482.                                             defaults: {
  483.                                                 anchor: '100%'
  484.                                             },
  485.  
  486.                                             items: [
  487.                                                 {
  488.                                                     xtype: 'textfield',
  489.                                                     name: 'label',
  490.                                                     id: ext_cmp_id_for('comment_label'),
  491.                                                     fieldLabel: 'Тема',
  492.                                                     anchor: '100%'
  493.                                                 },
  494.                                                 {
  495.                                                     xtype: 'textareafield',
  496.                                                     grow: true,
  497.                                                     name: 'body',
  498.                                                     id: ext_cmp_id_for('comment_body'),
  499.                                                     fieldLabel: 'Сообщение',
  500.                                                     anchor: '100%'
  501.                                                 }
  502.  
  503.                                             ],
  504.  
  505.                                             buttons: [
  506.                                                 {
  507.                                                     xtype: 'button',
  508.                                                     id: ext_cmp_id_for('comment_submit'),
  509.                                                     text: 'Добавить'
  510.                                                 },
  511.                                                 {
  512.                                                     xtype: 'button',
  513.                                                     text: 'Отмена',
  514.                                                     handler: "function(){
  515.      Ext.getCmp('#{ext_cmp_id_for('comment_panel')}').hide();
  516.    }".to_js
  517.                                                 }
  518.                                             ]
  519.                                         }
  520.                                     },
  521.                                 ]
  522.                             })
  523.  
  524.  
  525.   end
  526. %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement