1/*
2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 *    notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 *    notice, this list of conditions and the following disclaimer in the
11 *    documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26/**
27 * @extends {WebInspector.View}
28 * @constructor
29 */
30WebInspector.PanelEnablerView = function(identifier, headingText, disclaimerText, buttonTitle)
31{
32    WebInspector.View.call(this);
33    this.registerRequiredCSS("panelEnablerView.css");
34
35    this.element.addStyleClass("panel-enabler-view");
36    this.element.addStyleClass(identifier);
37
38    this.contentElement = document.createElement("div");
39    this.contentElement.className = "panel-enabler-view-content";
40    this.element.appendChild(this.contentElement);
41
42    this.imageElement = document.createElement("img");
43    this.contentElement.appendChild(this.imageElement);
44
45    this.choicesForm = document.createElement("form");
46    this.contentElement.appendChild(this.choicesForm);
47
48    this.headerElement = document.createElement("h1");
49    this.headerElement.textContent = headingText;
50    this.choicesForm.appendChild(this.headerElement);
51
52    var self = this;
53    function enableOption(text, checked) {
54        var label = document.createElement("label");
55        var option = document.createElement("input");
56        option.type = "radio";
57        option.name = "enable-option";
58        if (checked)
59            option.checked = true;
60        label.appendChild(option);
61        label.appendChild(document.createTextNode(text));
62        self.choicesForm.appendChild(label);
63        return option;
64    };
65
66    this.enabledForSession = enableOption(WebInspector.UIString("Only enable for this session"), true);
67    this.enabledAlways = enableOption(WebInspector.UIString("Always enable"), false);
68
69    this.disclaimerElement = document.createElement("div");
70    this.disclaimerElement.className = "panel-enabler-disclaimer";
71    this.disclaimerElement.textContent = disclaimerText;
72    this.choicesForm.appendChild(this.disclaimerElement);
73
74    this.enableButton = document.createElement("button");
75    this.enableButton.setAttribute("type", "button");
76    this.enableButton.textContent = buttonTitle;
77    this.enableButton.addEventListener("click", this._enableButtonCicked.bind(this), false);
78    this.choicesForm.appendChild(this.enableButton);
79}
80
81WebInspector.PanelEnablerView.prototype = {
82    _enableButtonCicked: function()
83    {
84        this.dispatchEventToListeners("enable clicked");
85    },
86
87    onResize: function()
88    {
89        this.imageElement.removeStyleClass("hidden");
90
91        if (this.element.offsetWidth < (this.choicesForm.offsetWidth + this.imageElement.offsetWidth))
92            this.imageElement.addStyleClass("hidden");
93    },
94
95    get alwaysEnabled() {
96        return this.enabledAlways.checked;
97    },
98
99    __proto__: WebInspector.View.prototype
100}
101