1<!DOCTYPE html>
2<!--
3Copyright 2016 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
7
8<link rel="import" href="/components/paper-button/paper-button.html">
9
10<link rel="import" href="/dashboard/elements/bisect-form.html">
11<link rel="import" href="/dashboard/static/simple_xhr.html">
12
13<polymer-element name="bisect-button" attributes="bisectInfo bugId xsrfToken">
14  <template>
15    <style>
16      /*
17       * A special style for the "enabled" attribute is used because when style
18       * is applied to the button element, it seems to override the paper-button
19       * [disabled] style.
20       * The selector #button:enabled doesn't work because the underlying
21       * element inside paper-button is a div, not a form element.
22       */
23      #button[enabled] {
24        background-color: #4285f4;
25        color: white;
26      }
27
28      /*
29       * Style for when this custom element when it has the class "mini".
30       * See: http://www.polymer-project.org/articles/styling-elements.html
31       */
32      :host(.mini) #button {
33        height: 22px;
34        line-height: 0.5em;
35        margin-left: 5px;
36        padding-top: 0;
37      }
38    </style>
39    <paper-button raised
40        id="button"
41        disabled?={{!canBisect}}
42        enabled?={{canBisect}}
43        on-click="{{onBisect}}">Bisect</paper-button>
44    <bisect-form
45        id="bisect"
46        xsrfToken="{{xsrfToken}}"
47        earlierRevision="{{bisectInfo.goodRev}}"
48        laterRevision="{{bisectInfo.badRev}}"
49        testPath="{{bisectInfo.testPath}}"
50        bugId="{{bugId}}"></bisect-form>
51  </template>
52  <script>
53    'use strict';
54
55    (function() {
56      Polymer('bisect-button', {
57        /**
58         * Initializes this element; this is an element lifecycle callback.
59         */
60        ready: function() {
61          this.update();
62        },
63
64        /**
65         * Updates the bisect button when the bisectInfo is set.
66         */
67        bisectInfoChanged: function() {
68          this.update();
69        },
70
71        /**
72         * Updates the canBisect state based on the bisectInfo state.
73         */
74        update: function() {
75          this.canBisect = false;
76          if (!this.bisectInfo) {
77            return;
78          }
79          var that = this;
80          simple_xhr.send(
81              '/can_bisect',
82              {
83                'test_path': this.bisectInfo.testPath,
84                'start_revision': this.bisectInfo.goodRev,
85                'end_revision': this.bisectInfo.badRev,
86              },
87              function loadCallback(responseBool) {
88                that.canBisect = responseBool;
89              },
90              function errorCallback(message) {
91                console.warn('Request to /can_bisect failed.', message);
92                that.canBisect = true;
93              });
94        },
95
96        /**
97         * Displays the bisect-form when the bisect button is clicked.
98         */
99        onBisect: function() {
100          this.$.bisect.show();
101        }
102      });
103    })();
104  </script>
105</polymer-element>
106