MVC

Application is divided into three core components: the
  model, the view, and the controller


View: the interface the user sees and interacts with


Model: manipulate the data in the application


Controller: handles the input event from the user interface
Why MVC for Titanium?

Better organization

Code reuse

Don’t like messy files
How MVC in Titanium?
Framework Used:

Appcelerator on Rails
Ruby-based generator

Model generator creates standard code for accessing
 data

Controller generator writes both View and Controller
 code

Migration generator who generate SQL code for table
 creation
View and Controller
Generate.rb ruby script generates files with
 template for view and controller.
To generate view and controller
Execute ruby script to generate view and
 controller
>>ruby scripts/generate.rb controller Products
Above command generate following files:
-Resources/controllers/products.js
-Resources/views/products.js
Template generated by ruby
           script for view
var ProductView =      View.extend({
      init: function(win, controller) {
           this._super(win, controller);
           this.layout();
      },
      layout: function() {
     Write code to Create
 button/ view/ text/ field ( all UIs)
 }
});
Template generated by ruby
         script for controller
var ProductController = Controller.extend({
      init: function(win) {
            this._super(win);
            this.view = new ProductView(win,
 this);
      },
      btnClicked: function(event) {
           Write code for Action to perform
      }
});
Instantiate controller
In app.js file:
//instantiate controller
var productController = new
  ProductController(pass window);
// this pass window will return value   which
  //we could open
Open passed window;
What skills do we need?
Javascript
Titanium
Ruby (if we know ,that ll be plus point)
Resources
http://primegap.net/
Google it.
Thank you

Mvc - Titanium

  • 1.
    MVC Application is dividedinto three core components: the model, the view, and the controller View: the interface the user sees and interacts with Model: manipulate the data in the application Controller: handles the input event from the user interface
  • 2.
    Why MVC forTitanium? Better organization Code reuse Don’t like messy files
  • 3.
    How MVC inTitanium? Framework Used: Appcelerator on Rails Ruby-based generator Model generator creates standard code for accessing data Controller generator writes both View and Controller code Migration generator who generate SQL code for table creation
  • 4.
    View and Controller Generate.rbruby script generates files with template for view and controller.
  • 5.
    To generate viewand controller Execute ruby script to generate view and controller >>ruby scripts/generate.rb controller Products Above command generate following files: -Resources/controllers/products.js -Resources/views/products.js
  • 6.
    Template generated byruby script for view var ProductView = View.extend({ init: function(win, controller) { this._super(win, controller); this.layout(); }, layout: function() { Write code to Create button/ view/ text/ field ( all UIs) } });
  • 7.
    Template generated byruby script for controller var ProductController = Controller.extend({ init: function(win) { this._super(win); this.view = new ProductView(win, this); }, btnClicked: function(event) { Write code for Action to perform } });
  • 8.
    Instantiate controller In app.jsfile: //instantiate controller var productController = new ProductController(pass window); // this pass window will return value which //we could open Open passed window;
  • 9.
    What skills dowe need? Javascript Titanium Ruby (if we know ,that ll be plus point)
  • 10.
  • 11.