UNPKG

4.31 kBJavaScriptView Raw
1// Generated by CoffeeScript 1.9.0
2(function() {
3 var assert, teacup,
4 __indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
5
6 module.exports = function(ko) {
7 var RuleTarget, html;
8 RuleTarget = (function() {
9 function RuleTarget(_arg) {
10 var $root, carriers, chosen, data, gateways;
11 data = _arg.data, $root = _arg.$root;
12 gateways = $root.gateways, carriers = $root.carriers;
13 assert(data != null, 'data is required');
14 assert(gateways != null, 'gateways is required');
15 assert(carriers != null, 'carriers is required');
16 this.source_registrant = ko.observable(data.source_registrant);
17 this.gwid = ko.observable(data.gwid);
18 this.carrierid = ko.observable(data.carrierid);
19 this.gatewayValid = ko.pureComputed((function(_this) {
20 return function() {
21 var _ref;
22 return (_this.gwid() == null) || (_ref = _this.gwid(), __indexOf.call(gateways, _ref) >= 0);
23 };
24 })(this));
25 this.carrierValid = ko.pureComputed((function(_this) {
26 return function() {
27 var _ref;
28 return (_this.carrierid() == null) || (_ref = _this.carrierid(), __indexOf.call(carriers, _ref) >= 0);
29 };
30 })(this));
31 chosen = this.source_registrant() === true ? 'registrant' : this.carrierid() != null ? 'carrier' : this.gwid() != null ? 'gateway' : void 0;
32 this.chosen = ko.observable(chosen);
33 this.carrier_chosen = ko.pureComputed((function(_this) {
34 return function() {
35 return _this.chosen() === 'carrier';
36 };
37 })(this));
38 this.gateway_chosen = ko.pureComputed((function(_this) {
39 return function() {
40 return _this.chosen() === 'gateway';
41 };
42 })(this));
43 this.visible = ko.pureComputed((function(_this) {
44 return function() {
45 return _this.chosen() !== 'none';
46 };
47 })(this));
48 return;
49 }
50
51 return RuleTarget;
52
53 })();
54 html = function() {
55 var a, input, label, li, name, text, ul;
56 name = "rule-target-" + (Math.random());
57 a = teacup.a, ul = teacup.ul, li = teacup.li, label = teacup.label, input = teacup.input, text = teacup.text;
58 return ul('.target', {
59 bind: {
60 visible: 'visible'
61 }
62 }, function() {
63 li('.choice', function() {
64 return label(function() {
65 input({
66 type: 'radio',
67 name: name,
68 value: 'registrant',
69 required: true,
70 bind: {
71 checked: 'chosen'
72 }
73 });
74 return text('Use Registrant');
75 });
76 });
77 li('.choice', function() {
78 label(function() {
79 input({
80 type: 'radio',
81 name: name,
82 value: 'carrier',
83 bind: {
84 checked: 'chosen'
85 },
86 required: true
87 });
88 return text('Use Carrier ');
89 });
90 return input({
91 list: 'carrier',
92 name: 'carrierid',
93 bind: {
94 value: 'carrierid',
95 enable: 'carrier_chosen'
96 },
97 required: true
98 });
99 });
100 return li('.choice', function() {
101 label(function() {
102 input({
103 type: 'radio',
104 name: name,
105 value: 'gateway',
106 bind: {
107 checked: 'chosen'
108 },
109 required: true
110 });
111 return text('Use Gateway ');
112 });
113 return input({
114 list: 'gateway',
115 name: 'gwid',
116 bind: {
117 value: 'gwid',
118 enable: 'gateway_chosen'
119 },
120 required: true
121 });
122 });
123 });
124 };
125 ko.components.register('rule-target', {
126 viewModel: RuleTarget,
127 template: teacup.render(html)
128 });
129 return RuleTarget;
130 };
131
132 teacup = require('teacup');
133
134 teacup.use((require('teacup-databind'))());
135
136 assert = require('assert');
137
138}).call(this);