Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%=
- ext_remote_component_config do |js|
- js.js_return Ext.create({
- xtype: 'container',
- layout: 'border',
- id: ext_cmp_id_for('news_container'),
- items: [
- {
- xtype: 'remotepanel',
- id: ext_cmp_id_for('sko_window'),
- title: '',
- modal: true,
- border: false,
- layout: 'fit',
- closable: true,
- closeAction: 'hide',
- dockable: true,
- forceReload: true,
- remoteCfg: {
- removeAllOnLoad: true,
- maskContainer: true,
- method: 'GET'
- },
- wndOptions: {
- onEsc: 'Ext.emptyFn',
- maximizable: true,
- maximized: true,
- alwaysOnTop: true
- }
- },
- {
- :xtype => 'railsform',
- :region => 'center',
- :edit => params[:edit],
- :no_edit => !@news_post.new_record? && !(current_user.admin? || @news_post.author?(current_user)),
- :show_delete => current_user.admin?,
- :url_prefix => '/news_posts',
- :rails_obj_id => params[:id],
- :baseParams => {:authenticity_token => form_authenticity_token},
- :ext_cfg => {:fileUpload => true},
- :listeners => {
- :actioncomplete => <<-EOJS.to_js,
- function(f, a){
- if (a.type == 'load') {
- if (a.result.data['news_post[is_sku_file]']) {
- Ext.getCmp('#{ext_cmp_id_for('sku_file')}').show();
- Ext.getCmp('#{ext_cmp_id_for('status_ids')}').hide();
- Ext.getCmp('#{ext_cmp_id_for('voc_region_ids')}').hide();
- Ext.getCmp('#{ext_cmp_id_for('voc_property_type_ids')}').hide();
- }else{
- Ext.getCmp('#{ext_cmp_id_for('sku_file')}').hide();
- Ext.getCmp('#{ext_cmp_id_for('status_ids')}').show();
- Ext.getCmp('#{ext_cmp_id_for('voc_region_ids')}').show();
- Ext.getCmp('#{ext_cmp_id_for('voc_property_type_ids')}').show();
- }
- }
- }
- EOJS
- },
- :rightButtons => [
- {
- :xtype => 'button',
- :text => 'Отправить рассылку',
- :off => @news_post.is_sent? || @news_post.new_record? || !(current_user.admin? || @news_post.author?(current_user)),
- :qtip => 'Отправить рассылку',
- #:iconCls => 'icon-application-get',
- :handler => <<-EOJS.to_js
- function(){
- Ext.Ajax.request({
- url : '/news_posts/#{@news_post.id}/send_email',
- method : 'POST',
- params : {
- _method : 'POST',
- authenticity_token : '#{form_authenticity_token}'
- },
- success : function(response) {
- var result = Ext.decode(response.responseText);
- if (result.success) {
- Ext.getCmp('#{ext_cmp_id_for('news_container')}').reloadParentRemote();
- } else {
- Ext.MessageBox.alert("Ошибка", result.errors.base);
- }
- }
- });
- }
- EOJS
- },
- ],
- :items => [
- {
- :name => 'news_post[dt]',
- :xtype => 'xdatefield',
- :fieldLabel => 'Дата'
- },
- {
- :name => 'news_post[label]',
- :xtype => 'textfield',
- :fieldLabel => 'Заголовок',
- :width => 155 + 350
- },
- {
- :name => 'news_post[body]',
- :xtype => 'textarea',
- :fieldLabel => 'Текст новости',
- :maxLength => 10000,
- :width => 155 + 350,
- id: ext_cmp_id_for('body_id'),
- },
- {
- :xtype => 'displayfield',
- :fieldLabel => 'Вкладки',
- :width => 155 + 350,
- :value => NewsPostSkuBlankTab.by_sku(current_user.try(:sku_id)).by_news_post(@news_post.try(:id)).first.try(:tabs),
- :off => !@news_post.try(:is_filling_info) || !current_user.sku?
- },
- {
- :xtype => 'fileuploadfield',
- :emptyText => 'Выберите файл',
- :fieldLabel => 'Файл',
- :name => 'news_post[news_file]',
- :buttonText => '',
- :buttonConfig => {
- :iconCls => 'icon-folder'
- }
- },
- {
- xtype: 'railsmulticombo',
- fieldLabel: 'Роли',
- off: !(current_user.admin? || current_user.hq?),
- values: roles_voc_with_news_stats(Role.news_roles_for(current_user), @news_post),
- name: 'news_post[role_ids]',
- listeners: {
- change: "function() {
- if (Ext.Array.indexOf(this.getValue(), 4) != -1) {
- Ext.getCmp('#{ext_cmp_id_for('nko_settings')}').show();
- } else {
- Ext.getCmp('#{ext_cmp_id_for('nko_settings')}').hide();
- }
- if(this.getValue().length == 1 && Ext.Array.indexOf(this.getValue(), 4) != -1){
- Ext.getCmp('#{ext_cmp_id_for('is_filling_info_id')}').show();
- }else{
- Ext.getCmp('#{ext_cmp_id_for('is_filling_info_id')}').hide();
- Ext.getCmp('#{ext_cmp_id_for('is_filling_info_id')}').setValue(false);
- }
- }".to_js
- }
- },
- {
- fieldLabel: 'Новость создана',
- off: @news_post.new_record? || @news_post.user.blank? || @news_post.user.admin? || @news_post.user.hq?,
- xtype: 'displayfield',
- name: 'news_post[created_by]',
- width: 155 + 500,
- },
- {
- xtype: 'fieldset',
- title: 'Настройка параметров отображения новости для пользователей санаторно-курортных организаций (роль Оператор СКО)',
- id: ext_cmp_id_for('nko_settings'),
- hidden: true,
- items: [
- {
- :xtype => 'xcheckbox',
- :name => 'news_post[is_sku_file]',
- :fieldLabel => 'Список из файла',
- :id => ext_cmp_id_for('is_sku_file'),
- :handler => <<-EOJS.to_js
- function() {
- if(this.checked) {
- Ext.getCmp('#{ext_cmp_id_for('sku_file')}').show();
- Ext.getCmp('#{ext_cmp_id_for('status_ids')}').hide();
- Ext.getCmp('#{ext_cmp_id_for('voc_region_ids')}').hide();
- Ext.getCmp('#{ext_cmp_id_for('voc_property_type_ids')}').hide();
- }else{
- Ext.getCmp('#{ext_cmp_id_for('sku_file')}').hide();
- Ext.getCmp('#{ext_cmp_id_for('status_ids')}').show();
- Ext.getCmp('#{ext_cmp_id_for('voc_region_ids')}').show();
- Ext.getCmp('#{ext_cmp_id_for('voc_property_type_ids')}').show();
- }
- }
- EOJS
- },
- {
- :xtype => 'fileuploadfield',
- :emptyText => 'Выберите файл',
- :fieldLabel => 'Список СКО',
- :id => ext_cmp_id_for('sku_file'),
- :name => 'news_post[sku_file]',
- :buttonText => '',
- :buttonConfig => {
- :iconCls => 'icon-folder'
- }
- },
- {
- xtype: 'railsmulticombo',
- fieldLabel: 'Статусы',
- id: ext_cmp_id_for('status_ids'),
- values: [
- {id: -1, label: 'Проект'},
- {id: 0, label: 'Опубликовано'},
- {id: 1, label: 'Согласовано'},
- {id: 2, label: 'Утверждено'},
- ],
- name: 'news_post[status_ids]',
- },
- {
- :xtype => 'xcheckbox',
- :name => 'news_post[is_filling_info]',
- :fieldLabel => 'Заполненность',
- :id => ext_cmp_id_for('is_filling_info_id'),
- :handler => <<-EOJS.to_js
- function() {
- if(this.checked) {
- Ext.getCmp('#{ext_cmp_id_for('body_id')}').setValue('Уважаемые коллеги, просьба заполнить(дозаполнить) следующие вкладки:');
- }else{
- Ext.getCmp('#{ext_cmp_id_for('body_id')}').setValue('');
- }
- }
- EOJS
- },
- {
- xtype: 'itemselector',
- name: 'news_post[voc_region_ids]',
- fieldLabel: 'Регионы',
- id: ext_cmp_id_for('voc_region_ids'),
- #anchor: '100%',
- height: 200,
- store: Ext.create('Ext.data.Store', {
- fields: ['id', 'label'],
- data: VocRegion.order(:code).as_json(only: [:id, :label])
- }),
- displayField: 'label',
- valueField: 'id',
- fromTitle: 'Доступно',
- toTitle: 'Выбрано',
- buttons: ['addall', 'add', 'remove', 'removeall'],
- msgTarget: 'under'
- },
- {
- xtype: 'checktreefield',
- name: 'news_post[voc_property_type_ids]',
- id: ext_cmp_id_for('voc_property_type_ids'),
- height: 200,
- #padding: '5 0 5 0',
- fieldLabel: 'Формы собственности',
- store: {
- xtype: 'store',
- fields: ['id', 'text', {
- name: 'checked',
- defaultValue: false
- }],
- data: [{id: -1, text: '[Не указано]', leaf: true}] + VocPropertyType.tree_data(VocPropertyType.roots)
- },
- toggleChildren: true,
- msgTarget: 'under'
- },
- ],
- },
- ]
- },
- {
- :xtype => 'railsgrid',
- :off => @news_post.new_record?,
- :region => 'south',
- :split => true,
- #:height => '50',
- :flex => 1,
- :url => @news_post.new_record? ? '/' : comments_news_post_path(@news_post),
- :url_prefix => @news_post.new_record? ? '/' : comments_news_post_path(@news_post),
- :root => 'comments',
- :title => 'Вопросы',
- :no_add_button => true,
- :no_view_button => true,
- :no_search => true,
- #:no_bbar => true,
- :totalProperty => 'res',
- :request_forgery_protection_token => request_forgery_protection_token,
- :form_authenticity_token => form_authenticity_token,
- :ext_cfg => {
- viewConfig: {
- getRowClass: "function(record) {
- return record.get('no_answer') ? 'x-grid3-row-highlight-pink' : '';
- }".to_js
- }
- },
- :fields => [
- {
- :name => :label,
- :label => 'Тема'
- },
- {
- :name => :user_label,
- :label => 'Пользователь'
- },
- {
- :name => :org_label,
- :label => 'Организация'
- },
- {
- :name => :dt,
- :label => 'Дата',
- :type => 'datetime'
- },
- ],
- :row_expander => {
- :rowBodyTpl => Ext::XTemplate.new(<<-EOTPL)
- <p>{body}</p>
- <tpl if="Ext.isArray(answers)">
- <p><b>Ответы</b></p>
- <table class="row-inner-table">
- <tpl for="answers">
- <tr>
- <td>{label}</td>
- <td>{user_label}</td>
- <td>{org_label}</td>
- <td>{dt:date("m.d.Y H:i")}</td>
- </tr>
- <tr>
- <td colspan=3>{body}</td>
- </tr>
- </tpl>
- </table>
- </tpl>
- EOTPL
- },
- :tbar_left => current_user.no_edit ? [] : [
- {
- xtype: 'button',
- iconCls: 'icon-add',
- text: 'Добавить вопрос',
- handler: <<-EJS.to_js
- function() {
- var grid = this.findParentByType('railsgrid');
- Ext.getCmp('#{ext_cmp_id_for('comment_panel')}').show();
- Ext.getCmp('#{ext_cmp_id_for('comment_label')}').setValue('');
- Ext.getCmp('#{ext_cmp_id_for('comment_body')}').setValue('');
- Ext.getCmp('#{ext_cmp_id_for('comment_submit')}').setHandler(function(){
- var self = this;
- self.disable();
- Ext.Ajax.request({
- url : '#{@news_post.new_record? ? '' : comment_news_post_path(@news_post, :ext_json)}',
- method : 'POST',
- params : {
- _method : 'POST',
- label : Ext.getCmp('#{ext_cmp_id_for('comment_label')}').getValue(),
- body : Ext.getCmp('#{ext_cmp_id_for('comment_body')}').getValue(),
- authenticity_token : '#{form_authenticity_token}'
- },
- success : function(response) {
- self.enable();
- var result = Ext.decode(response.responseText);
- if (result.success) {
- Ext.getCmp('#{ext_cmp_id_for('comment_panel')}').hide();
- grid.getStore().reload();
- } else if (result.errors) {
- if (result.errors['news_comment[label]'])
- Ext.getCmp('#{ext_cmp_id_for('comment_label')}').markInvalid(result.errors['news_comment[label]']);
- if (result.errors['news_comment[body]'])
- Ext.getCmp('#{ext_cmp_id_for('comment_body')}').markInvalid(result.errors['news_comment[body]']);
- } else {
- Ext.MessageBox.alert("Ошибка", 'Нет ответа от сервера');
- }
- }
- });
- });
- }
- EJS
- }
- ],
- :row_actions => current_user.no_edit ? [] : [
- {
- :iconCls => 'icon-form-edit',
- :tooltip => 'Ответить',
- # :isDisabled => 'function(view, rowIndex, colIndex, item, record) {
- # return !!record.get("excluded_at")
- # }'.to_js,
- :handler => <<-EJS.to_js
- function(view, rowIndex, colIndex, item, e, record) {
- var grid = view.up('railsgrid,railstreegrid');
- Ext.getCmp('#{ext_cmp_id_for('comment_panel')}').show();
- Ext.getCmp('#{ext_cmp_id_for('comment_label')}').setValue('');
- Ext.getCmp('#{ext_cmp_id_for('comment_body')}').setValue('');
- Ext.getCmp('#{ext_cmp_id_for('comment_submit')}').setHandler(function(){
- var self = this;
- self.disable();
- Ext.Ajax.request({
- url : '#{@news_post.new_record? ? '' : comment_news_post_path(@news_post, :ext_json)}',
- method : 'POST',
- params : {
- _method : 'POST',
- parent_id: record.get('id'),
- label : Ext.getCmp('#{ext_cmp_id_for('comment_label')}').getValue(),
- body : Ext.getCmp('#{ext_cmp_id_for('comment_body')}').getValue(),
- authenticity_token : '#{form_authenticity_token}'
- },
- success : function(response) {
- self.enable();
- var result = Ext.decode(response.responseText);
- if (result.success) {
- Ext.getCmp('#{ext_cmp_id_for('comment_panel')}').hide();
- grid.getStore().reload();
- } else if (result.errors) {
- if (result.errors['news_comment[label]'])
- Ext.getCmp('#{ext_cmp_id_for('comment_label')}').markInvalid(result.errors['news_comment[label]']);
- if (result.errors['news_comment[body]'])
- Ext.getCmp('#{ext_cmp_id_for('comment_body')}').markInvalid(result.errors['news_comment[body]']);
- } else {
- Ext.MessageBox.alert("Ошибка", 'Нет ответа от сервера');
- }
- }
- });
- });
- }
- EJS
- },
- {
- :iconCls => 'icon-view',
- :tooltip => 'Открыть СКО',
- :handler => <<-EOJS.to_js,
- function() {
- var win = Ext.getCmp('#{ext_cmp_id_for('sko_window')}');
- console.log(win);
- win.show();
- win.reloadRailsCmp('#{ sku_path(3203) }');
- }
- EOJS
- }
- ]
- },
- {
- xtype: 'window',
- width: 400,
- height: 200,
- title: '',
- noDefaultButtons: true,
- id: ext_cmp_id_for('comment_panel'),
- layout: 'fit',
- modal: true,
- closeAction: 'hide',
- items: {
- xtype: 'form',
- bodyPadding: 5,
- border: false,
- layout: 'anchor',
- defaults: {
- anchor: '100%'
- },
- items: [
- {
- xtype: 'textfield',
- name: 'label',
- id: ext_cmp_id_for('comment_label'),
- fieldLabel: 'Тема',
- anchor: '100%'
- },
- {
- xtype: 'textareafield',
- grow: true,
- name: 'body',
- id: ext_cmp_id_for('comment_body'),
- fieldLabel: 'Сообщение',
- anchor: '100%'
- }
- ],
- buttons: [
- {
- xtype: 'button',
- id: ext_cmp_id_for('comment_submit'),
- text: 'Добавить'
- },
- {
- xtype: 'button',
- text: 'Отмена',
- handler: "function(){
- Ext.getCmp('#{ext_cmp_id_for('comment_panel')}').hide();
- }".to_js
- }
- ]
- }
- },
- ]
- })
- end
- %>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement