Module: KirguduBase::Controllers::BasicActions::Common::Ajax::InplaceEditActions

Defined in:
app/helpers/kirgudu_base/controllers/basic_actions.rb

Instance Method Summary collapse

Instance Method Details

#edit_inplaceObject



1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
# File 'app/helpers/kirgudu_base/controllers/basic_actions.rb', line 1206

def edit_inplace

  unless self.class.respond_to?(:get_kb_page)
    render text: '<span style = "color: red;"><b>ERROR OCCURRED!!!</b></span>'
    return
  end

  local_data = {}
  local_data[:page] = self.class.get_kb_page(:update)


  unless local_data[:page]
    render text: '<span style = "color: red;"><b>ERROR OCCURRED!!!</b></span>'
    return
  end


  local_data[:entry] = self.entry_class.get_entry_by_id(params[:id], nil, {logger: string_logger})
  if local_data[:entry]
    result_string = ''
    begin
      unless local_data[:entry][params[:field_name]] == params[:value]
        local_data[:entry][params[:field_name]] = params[:value]
        local_data[:entry].updated_at = Time.now
        local_data[:entry].updater = @current_user
        unless local_data[:entry].save
          result_string = '<span style = "color: red;"><b>FAILED TO SAVE!!!</b></span>'
        end
      end
    rescue
      result_string = '<span style = "color: red;"><b>ERROR OCCURRED!!!</b></span>'
    end
    if result_string.blank?
      begin
        result_string = local_data[:entry].send(params[:field_name])
      rescue
        result_string = '<span style = "color: red;"><b>ERROR OCCURRED!!!</b></span>'
      end
    end

    render text: result_string
  else
    render text: '<span style = "color: red;"><b>NOT FOUND!!!</b></span>'
  end
end