Debian Codegraph @

htrace-htraced/go/web/app/predicate_view.js

raw
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 var htrace = htrace || {};
21
22 htrace.PredicateView = Backbone.View.extend({
23 initialize: function(options) {
24 this.el = options.el;
25 this.index = options.index;
26 this.ptype = options.ptype;
27 this.searchView = options.searchView;
28 },
29
30 events: {
31 "click .closeButton": "remove",
32 },
33
34 render: function() {
35 this.$el.html(_.template($("#predicate-template").html())
36 ({ desc: this.ptype.name, id: this.index }))
37 if (this.getText() === "") {
38 $(this.$el).find(".form-control").val(this.ptype.getDefaultValue());
39 }
40 console.log(this.toString() + "#render");
41 return this;
42 },
43
44 // Handle the user removing this predicate.
45 remove: function() {
46 this.searchView.removePredicateView(this);
47 Backbone.View.prototype.remove.apply(this, arguments);
48 },
49
50 // Get the text which the user has entered in.
51 getText: function() {
52 return $(this.$el).find(".form-control").val().trim();
53 },
54
55 // Get the predicate expressed by this view.
56 // Throw an exception if the predicate can't be parsed.
57 getPredicate: function() {
58 return new htrace.Predicate({
59 ptype: this.ptype,
60 val: this.ptype.normalize(this.getText())
61 });
62 },
63
64 toString: function() {
65 return "PredicateView(this.el=" + this.el + ", this.index=" +
66 this.index + ", this.ptype='" + this.ptype.name + "')";
67 }
68 });