UNPKG

4.62 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 = (require('ccnq-ko'))('rule-target', function(ko) {
7 var RuleTarget;
8 RuleTarget = (function() {
9 function RuleTarget(data) {
10 assert(data != null, 'data is required');
11 this.source_registrant = ko.observable(data.source_registrant);
12 this.gwid = ko.observable(data.gwid);
13 this.carrierid = ko.observable(data.carrierid);
14 this._validated = ko.observable(false);
15 return;
16 }
17
18 return RuleTarget;
19
20 })();
21 this.view(function(_arg) {
22 var $root, carrier_valid, carriers, chosen, gateway_valid, gateways, value;
23 value = _arg.value, $root = _arg.$root;
24 assert(value instanceof RuleTarget, 'value should be an instance of RuleTarget');
25 gateways = $root.gateways, carriers = $root.carriers;
26 assert(gateways != null, 'gateways is required');
27 assert(carriers != null, 'carriers is required');
28 chosen = value.source_registrant() === true ? 'registrant' : value.carrierid() != null ? 'carrier' : value.gwid() != null ? 'gateway' : void 0;
29 this.chosen = ko.observable(chosen);
30 this.name = "rule-entry-chosen-" + (Math.random());
31 this.gwid = value.gwid;
32 this.carrierid = value.carrierid;
33 gateway_valid = function(id) {
34 return (id != null) && __indexOf.call(gateways, id) >= 0;
35 };
36 carrier_valid = function(id) {
37 return (id != null) && __indexOf.call(carriers, id) >= 0;
38 };
39 this.valid = ko.computed((function(_this) {
40 return function() {
41 switch (_this.chosen()) {
42 case 'registrant':
43 _this.gwid(null);
44 _this.carrierid(null);
45 return true;
46 case 'gateway':
47 _this.carrierid(null);
48 return gateway_valid(_this.gwid());
49 case 'carrier':
50 _this.gwid(null);
51 return carrier_valid(_this.carrierid());
52 default:
53 _this.gwid(null);
54 _this.carrierid(null);
55 return false;
56 }
57 };
58 })(this));
59 this.chosen.subscribe((function(_this) {
60 return function() {
61 return value.source_registrant(_this.chosen() === 'registrant');
62 };
63 })(this));
64 this.valid.subscribe((function(_this) {
65 return function(is_valid) {
66 return value._validated(is_valid);
67 };
68 })(this));
69 });
70 return this.html(function(_arg) {
71 var a, input, label, li, text, ul;
72 a = _arg.a, ul = _arg.ul, li = _arg.li, label = _arg.label, input = _arg.input, text = _arg.text;
73 return ul('.target', function() {
74 li('.choice', function() {
75 return label(function() {
76 input({
77 type: 'radio',
78 value: 'registrant',
79 required: true,
80 bind: {
81 checked: 'chosen',
82 attr: '{name:name}'
83 }
84 });
85 return text('Use Registrant');
86 });
87 });
88 li('.choice', function() {
89 label(function() {
90 input({
91 type: 'radio',
92 value: 'carrier',
93 bind: {
94 checked: 'chosen',
95 attr: '{name:name}'
96 },
97 required: true
98 });
99 return text('Use Carrier ');
100 });
101 return input({
102 list: 'carrier',
103 name: 'carrierid',
104 bind: {
105 value: 'carrierid',
106 enable: 'chosen() === "carrier"'
107 },
108 required: true
109 });
110 });
111 return li('.choice', function() {
112 label(function() {
113 input({
114 type: 'radio',
115 value: 'gateway',
116 bind: {
117 checked: 'chosen',
118 attr: '{name:name}'
119 },
120 required: true
121 });
122 return text('Use Gateway ');
123 });
124 return input({
125 list: 'gateway',
126 name: 'gwid',
127 bind: {
128 value: 'gwid',
129 enable: 'chosen() === "gateway"'
130 },
131 required: true
132 });
133 });
134 });
135 });
136 });
137
138 teacup = require('teacup');
139
140 teacup.use((require('teacup-databind'))());
141
142 assert = require('assert');
143
144}).call(this);