Module: BackendApiAdapter::InstanceMethods

Included in:
MongoBureau
Defined in:
lib/mongo_bureau.rb

Instance Method Summary collapse

Instance Method Details

#backend_clone_form(url, opts = {}) ⇒ Object



44
45
46
47
48
# File 'lib/mongo_bureau.rb', line 44

def backend_clone_form(url, opts={})
  backend_form(url, [], {:submit_text=>'CLONE', :method=>'POST'}.update(opts)) do |out|
    out << "<input type='hidden' name='clone_id' value='#{self.id}' />\n"
  end
end

#backend_deleteObject



16
# File 'lib/mongo_bureau.rb', line 16

def backend_delete; delete; end

#backend_delete_form(url, opts = {}) ⇒ Object



43
# File 'lib/mongo_bureau.rb', line 43

def backend_delete_form(url, opts={}); backend_form(url, [], {:submit_text=>'X', :method=>'DELETE'}.update(opts)){}; end

#backend_fields(cols) ⇒ Object

Silly but usable form prototype Not really meant to be used in a real case It uses a textarea for everything Override it Or even better, use Sequel-Crushyform plugin instead



54
55
56
57
58
59
60
61
62
# File 'lib/mongo_bureau.rb', line 54

def backend_fields(cols)
  o = ''
  cols.each do |c|
    identifier = "#{id}-#{self.class}-#{c}"
    o << "<label for='#{identifier}'>#{c.to_s.capitalize}</label><br />\n"
    o << "<textarea id='#{identifier}' name='model[#{c}]'>#{self[c]}</textarea><br />\n"
  end
  o
end

#backend_form(url, cols = nil, opts = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/mongo_bureau.rb', line 20

def backend_form(url, cols=nil, opts={})
  cols ||= default_backend_columns
  if block_given?
    fields_list = ''
    yield(fields_list)
  else
    fields_list = respond_to?(:crushyform) ? crushyform(cols) : backend_fields(cols)
  end
  o = "<form action='#{url}' method='POST' #{"enctype='multipart/form-data'" if fields_list.match(/type='file'/)} class='backend-form'>\n"
  o << backend_form_title unless block_given?
  o << fields_list
  opts[:method] = 'PUT' if (opts[:method].nil? && !self.new?)
  o << "<input type='hidden' name='_method' value='#{opts[:method]}' />\n" unless opts[:method].nil?
  o << "<input type='hidden' name='_destination' value='#{opts[:destination]}' />\n" unless opts[:destination].nil?
  o << "<input type='hidden' name='_submit_text' value='#{opts[:submit_text]}' />\n" unless opts[:submit_text].nil?
  o << "<input type='hidden' name='_no_wrap' value='#{opts[:no_wrap]}' />\n" unless opts[:no_wrap].nil?
  cols.each do |c|
    o << "<input type='hidden' name='fields[]' value='#{c}' />\n"
  end
  o << "<input type='submit' name='save' value='#{opts[:submit_text] || 'SAVE'}' />\n"
  o << "</form>\n"
  o
end

#backend_form_titleObject



63
# File 'lib/mongo_bureau.rb', line 63

def backend_form_title; self.new? ? "<h2><span>New #{model.human_name}</span></h2>\n" : "<h2><span>Edit #{self.to_label}</span></h2>\n"; end

#backend_put(fields) ⇒ Object



17
# File 'lib/mongo_bureau.rb', line 17

def backend_put(fields); update_doc(fields); end

#backend_save?Boolean

Returns:

  • (Boolean)


19
# File 'lib/mongo_bureau.rb', line 19

def backend_save?; !save.nil?; end

#backend_showObject



64
# File 'lib/mongo_bureau.rb', line 64

def backend_show; 'OK'; end

#backend_valuesObject



18
# File 'lib/mongo_bureau.rb', line 18

def backend_values; @doc; end