Nano editor Comment/Uncomment in GNU Nano editor using Alt+3 shortcut

GNU Nano editor adjust comment literal for PHP / C / C++

If you are a UNIX lover and fan of Nano text editor then while writing C / C++ code, you would like to put comments using Short-Cut key i.e. Alt+3. But the problem is, Nano puts the char # as comment literal instead of //. This happened because the default literal is # unless it is defined in configurations.

How to fix?

Continue reading

HTML, CSS : Beautiful radio and checkboxes

Radio:

There are two ways you can put label on radios

  • Put for="id_of_your_radio" in the label tag
  • Put the radio inside of lable tag; no need of for attribute. It will be implicit
    • <label>
       <input id="sex-other" type="radio" name="sex" value="others" /> Other
      </label>
    • This technique is more cleaner, intuitive and maintainable from my perspective.

Our Target:

The basic idea is: we want to modify the label according to our design demands. But the later technique explained above has label as parent to input tag; CSS has limitation; we cannot select parent on the basis of child. In our case child (input) changes events and need to modify the label.

So going with the former technique

 

See here for More details

Rails : Customize Rails Admin engine

I wondered what these terms like collection and member mean.

member :activate do
  only ['Contractor']
  i18n_key :activate
end

collection :painter_photos do
  i18n_key :painter_photos
end

member: These are actions applicable to individual records in the model. This will show up in every row like.

collection: applicable to the model as a whole

How to add custom action in particular row?

member :activate do
  only ['Contractor']
  i18n_key :activate
end

for this you would need to put

# in views/rails_admin/main/activate.haml
- if @object.is_a?(Contractor)
  - if @object.active?
    %p Already Activated
  - else
    %p You are about to activate a contractor.
    %p
      Name:
      %b
        = @object.full_name
    = link_to "Activate Contractor", main_app.admin_activate_contractor_path(@object), confirm: "Are you sure?", class: "btn"
- else
  %p Sorry, only contractors can be activated.

and

# in rails_admin.en.yml
activate:
  title: "Activate"
  menu: "Activate"
  breadcrumb: "Activate"

 

Custom Label

field :painters, :boolean do
  label do
    "Send to all contractors"
  end

  render do
    content =  bindings[:form].check_box :painters
    bindings[:view].render inline: content
  end
end

Customize the Edit / New Form

You can customize the button names in the form but in a tricky way. For example lets try to change the button names like Save to Send and so.

copy the file

https://github.com/sferik/…/_submit_buttons.html.haml this page in your repo at “views/rails_admin/main/_submit_button.html.haml”

and put conditional like

- if params['model_name']  == 'broadcast' && params['action'] == 'new'
  %button.btn.btn-primary{type: "submit", name: "_save", :'data-disable-with' => t("admin.models.broadcast.save")}
    %i.icon-white.icon-email
    = t('admin.models.broadcast.save')
- else
  %button.btn.btn-primary{type: "submit", name: "_save", :'data-disable-with' => t("admin.form.save")}
    %i.icon-white.icon-ok
    = t("admin.form.save")

and add some i18n keys in rails_admin.en.yml like

en:
  admin:
    loading: "Loading..."
    home:
      name: "Home"
    pagination:
      previous: "&laquo; Prev"
      next: "Next &raquo;"
      truncate: "…"
    models:
      broadcast:
        save: 'Send Message'
        save_and_add_another: 'Send and prepare for next'
        save_and_edit: 'Send and Edit'

DataTables : Customizing navigation button

var $workflowTable = $('.workflow-table');
  $workflowTable.dataTable(
    {
      'iDisplayLength': 10,
      'fnDrawCallback': function (oSettings) {
        if (oSettings._iDisplayLength > oSettings.fnRecordsDisplay()) {
          $(oSettings.nTableWrapper).find('.dataTables_paginate').hide();
        }
        var curPage = Math.ceil(oSettings._iDisplayStart / oSettings._iDisplayLength) + 1;
        var lastPage = Math.ceil( oSettings.fnRecordsDisplay() / oSettings._iDisplayLength );

        if (curPage === 1){
          $(oSettings.nTableWrapper).find('.paginate_disabled_previous').hide();
        }else{
          $(oSettings.nTableWrapper).find('.paginate_enabled_previous').show();
        }
        if(curPage === lastPage){
          $(oSettings.nTableWrapper).find('.paginate_disabled_next').hide();
        }else{
          $(oSettings.nTableWrapper).find('.paginate_enabled_next').show();
        }
      }
    }
  );