master
 1class AppDelegate
 2  def application(application, didFinishLaunchingWithOptions:launchOptions)
 3    @window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
 4    #controller_factory = ControllerFactory.new
 5    #@window.rootViewController = UINavigationController.alloc.initWithRootViewController(controller_factory.create(SearchController))
 6    #@window.makeKeyAndVisible
 7
 8    @form = Formotion::Form.new({
 9      sections: [
10        {
11          title: "Review",
12          rows: [
13            { title: "Broth", key: :Broth, type: :slider, range: (1..10), value: 7 },
14            { title: "Beef", key: :Beef, type: :slider, range: (1..10), value: 7 },
15            { title: "Noodles", key: :Noodles, type: :slider, range: (1..10), value: 7 },
16            { title: "Vegetables", key: :Vegetables, type: :slider, range: (1..10), value: 7 },
17            { title: "Bowl Size", key: :Bowl, type: :slider, range: (1..10), value: 7 },
18            { title: "Sauces", key: :Sauces, type: :slider, range: (1..10), value: 7 },
19            { title: "Presentation", key: :Presentation, type: :slider, range: (1..10), value: 7 },
20            { title: "Ambiance", key: :Ambiance, type: :slider, range: (1..10), value: 7 },
21          ]
22        },
23        {
24          rows: [ { title: "Submit", type: :submit, }]
25        }]
26    })
27    @form.on_submit do |form|
28      BW::Location.get do |result|
29        BW::Location.stop
30        p form.render
31        #location = Restaurant.new(@textbox.text, result[:to].latitude, result[:to].longitude)
32        #location.save
33        #{:broth=>7, :beef=>7, :noodles=>7, :vegetables=>7, :bowl=>7, :sauces=>7, :presentation=>7.40510940551758, :ambiance=>4.34687423706055}
34        BW::HTTP.post("http://localhost:3000/api/v1/reviews", to_hash(form.render) ) do |response|
35          #p response
36        end
37      end
38    end
39
40    @form_controller = Formotion::FormController.alloc.initWithForm(@form)
41    @window.rootViewController = @form_controller
42    @window.makeKeyAndVisible
43
44    true
45  end
46
47  def to_hash(hash)
48    result = {
49      payload:
50      {
51        review:
52        {
53          uid: 1,
54          latitude: @latitude,
55          longitude: @longitude,
56          ratings: hash.keys.map { |key| {:score => hash[key], :category => key} }
57        }
58      }
59    }
60    p result
61    result
62  end
63end