Feedback form model

we will have two classes for the Feedback function.

Feedbacks - the model to query and create data entry to MongoLab

FeedbacksView - the view logic, mostly jQuery stuff, to post and show feedbacks.

 1// Feedbacks Module
 2app.Feedbacks = (function(){
 3  function Feedbacks(){
 4    var key = '<KEY HERE>';
 5    this.url = 'https://api.mongolab.com/api/1/databases/phonegap-test/collections/feedbacks?apiKey=' + key;
 6  }
 7  Feedbacks.prototype.post = function (name, email, message, callback) {
 8    var data = JSON.stringify({
 9      name: name,
10      email: email,
11      message: message,
12    });
13
14    $.ajax({
15      url: this.url,
16      type: "POST",
17      contentType: "application/json",
18      crossDomain: true,
19      dataType: "json",
20      data: JSON.stringify({
21        name: name,
22        email: email,
23        message: message,
24      }),
25      success: function (data) {
26        console.log('saved to mongo, response:', data);
27        // call the callback function
28        callback && callback(data);
29      }
30    });
31  }
32  return Feedbacks;
33}).call(this); // End Feedbacks Module
34
35// example usage: (new app.Feedbacks()).post('Thomas', 'test@example.com', 'Hello World');

What’s next? We’re going to take a look at “Feedback form view”.

overlaied image when clicked on thumbnail

Makzan | Mobile web app dev with phonegap | Table of Content