File size: 1,627 Bytes
c02f046
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var Base = require('./base');

var view = function(name, decimal){

  Base.call(this, name);

  this.decimal = !!decimal ? decimal : 2;
};
view.prototype = new Base;
view.prototype.constructor = view;
module.exports = view;

view.prototype.step = function(){

  var step = '.';
  for(var i = 1; i < this.decimal; i++){
    step += '0';
  }
  step += '1';
  return step;
};

view.prototype.getValue = function(){

  var value = Base.prototype.getValue.call(this);
  if(typeof value == "string"){
    value = value.replace(',', '.');
  }

  return !!value ? parseFloat(value) : null;
};

view.prototype.makeInputs = function(){

  var self = this;
  this.inputs.html('');

  var input = CE('input').attr({'type': 'number', 'step': this.step(), 'min': 0, 'max': 10, name: this.name});
  this.inputs.append(input);

  if(!!this.value) input.val(this.value.formatMoney(self.decimal, '.', ''));
  if(!this._edit)  input.attr('disabled', 'disabled');

  input.keyup(function(e){
      var $this  = $(this);
      var value = $this.val();
      var value  = value.replace('.','');
      var value  = parseInt(value);
      self.value = (value/Math.pow(10, self.decimal)).formatMoney(self.decimal, '.', '');
      $this.val(self.value);
      self.fireEvent('keyup', [this, this.value]);

  }).focusout(function(e){
      var $this = $(this);
      var value = $this.val().replace('.','');
      var value = parseInt(value);
      if(value == 0){
        self.value = null; 
        $this.val('');
      }
      self.fireEvent('keyup', [this, this.value]);
  }).change(function(e){

    self.onchange.call(self, self.value);

  });
}