Advertisement
Serafim

Untitled

Aug 14th, 2013
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. namespace('Models', function() {
  2.   return this.Item = (function(_super) {
  3.  
  4.     __extends(Item, _super);
  5.  
  6.     function Item() {
  7.       return Item.__super__.constructor.apply(this, arguments);
  8.     }
  9.  
  10.     Item.prototype.model = {
  11.       name: Item.name,
  12.       parent: _super,
  13.       table: Item.name.toLowerCase(),
  14.       proto: Item
  15.       /*
  16.       */
  17.  
  18.     };
  19.  
  20.     Item.prototype.buy = function(cb, count) {
  21.       var _this = this;
  22.       if (cb == null) {
  23.         cb = (function() {});
  24.       }
  25.       if (count == null) {
  26.         count = 1;
  27.       }
  28.       return Server.post("items/" + (id()) + "/purchase.json", {
  29.         'count': count
  30.       }, function(data) {
  31.         return cb(data);
  32.       });
  33.     };
  34.  
  35.     Item.prototype.sell = function(cb, count) {
  36.       var _this = this;
  37.       if (cb == null) {
  38.         cb = (function() {});
  39.       }
  40.       if (count == null) {
  41.         count = 1;
  42.       }
  43.       return Server.post("items/" + (id()) + "/sale.json", {
  44.         'count': count
  45.       }, function(data) {
  46.         return cb(data);
  47.       });
  48.     };
  49.  
  50.     Item.getByLevel = function(level) {
  51.       return this.findBy('level', level);
  52.     };
  53.  
  54.     Item.getDocuments = function() {
  55.       return this.getByType('d');
  56.     };
  57.  
  58.     Item.getOrganizations = function() {
  59.       return this.getByType('o');
  60.     };
  61.  
  62.     Item.getPeople = function() {
  63.       return this.getByType('p');
  64.     };
  65.  
  66.     Item.types = {
  67.       d: 'documents',
  68.       o: 'organizations',
  69.       p: 'people'
  70.     };
  71.  
  72.     Item.getByType = function(type) {
  73.       return this.where('type = %1', [this.types[type]]).get();
  74.     };
  75.  
  76.     return Item;
  77.  
  78.   })(ArJs.Model);
  79. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement