15
15
var namespace = Y.namespace('lp.registry.distroseries.widgets');
19
* A form row matching that which LaunchpadForm presents, containing a
20
* field (defined in a subclass), and an optional label and
23
* @class FormRowWidget
27
FormRowWidget = function() {
28
FormRowWidget.superclass.constructor.apply(this, arguments);
31
Y.mix(FormRowWidget, {
33
NAME: 'formRowWidget',
43
setter: function(value, name) {
44
this.fieldNode.all("input, select").set("name", value);
49
* The top label for the field.
55
return this.labelNode.get("text");
57
setter: function(value, name) {
58
this.labelNode.set("text", value);
63
* A dictionary {link:link, text:text} to populate
64
* the pop-up help for the field.
70
return {link:this.helpNode.one('a')
73
.one('.invisible-link')
76
setter: function(value, name) {
77
if ((value.link !== undefined) &&
78
(value.text !== undefined)) {
79
this.helpNode.one('a').set("href", value.link);
80
this.helpNode.one('.invisible-link')
81
.set("text", value.text);
82
this.helpNode.removeClass('unseen');
85
this.helpNode.addClass('unseen');
91
* A description shown near the field.
97
return this.descriptionNode.get("text");
99
setter: function(value, name) {
100
this.descriptionNode.set("text", value);
107
Y.extend(FormRowWidget, Y.Widget, {
109
BOUNDING_TEMPLATE: "<tr></tr>",
111
CONTENT_TEMPLATE: '<td colspan="2"></td>',
113
initializer: function(config) {
114
this.labelNode = Y.Node.create("<label />");
115
this.helpNode = Y.Node.create(('<span class="helper unseen">'+
117
'target="help" class="sprite maybe"> ' +
118
'<span class="invisible-link"></span></a></span>'));
119
this.fieldNode = Y.Node.create("<div></div>");
120
this.descriptionNode = Y.Node.create('<p class="formHelp" />');
121
this.spinnerNode = Y.Node.create(
122
'<img src="/@@/spinner" alt="Loading..." />');
125
renderUI: function() {
126
this.get("contentBox")
127
.append(this.labelNode)
128
.append(this.helpNode)
129
.append(this.fieldNode)
130
.append(this.descriptionNode);
136
* @method showSpinner
138
showSpinner: function() {
139
this.fieldNode.empty().append(this.spinnerNode);
145
* @method hideSpinner
147
hideSpinner: function() {
148
this.spinnerNode.remove();
156
showError: function(error) {
157
var message = Y.Node.create('<p />').set("text", error);
158
this.fieldNode.empty().append(message);
159
Y.lazr.anim.red_flash({node: message}).run();
164
namespace.FormRowWidget = FormRowWidget;
17
var formwidgets = Y.lp.app.formwidgets;
167
21
* A table to display, order, delete the selected parent series. Each parent
468
* A form row matching that which LaunchpadForm presents, containing a
469
* list of checkboxes, and an optional label and description.
471
* @class ChoiceListWidget
473
var ChoiceListWidget;
475
ChoiceListWidget = function() {
476
ChoiceListWidget.superclass.constructor.apply(this, arguments);
479
Y.mix(ChoiceListWidget, {
481
NAME: 'choiceListWidget',
486
* An array of strings from which to choose.
492
return this.fieldNode.all("li > input").get("value");
494
setter: function(value, name) {
495
var choices = Y.Array.unique(value).sort();
496
var list = Y.Node.create("<ul />");
500
var item = self._createChoice(choice);
504
this.fieldNode.empty().append(list);
509
* The current selection.
514
setter: function(value, name) {
515
if (!Y.Lang.isArray(value)) {
518
this.fieldNode.all("li > input").each(
522
value.indexOf(node.get("value")) >= 0);
528
this.fieldNode.all("li > input").each(
530
if (node.get("checked")) {
531
choice.push(node.get("value"));
535
if (this.get("type") === "radio") {
536
if (choice.length === 0) {
539
else if (choice.length === 1) {
551
* The input type to display. Choose from "checkbox" or "radio".
557
setter: function(value, name) {
558
this.fieldNode.all("li > input").set("type", value);
566
Y.extend(ChoiceListWidget, FormRowWidget, {
569
* Helper method to create an entry for the select widget.
571
* @method _createChoice
573
_createChoice: function(choice) {
574
var field_name = this.get("name");
575
var field_type = this.get("type");
576
var item = Y.Node.create(
577
"<li><input /> <label /></li>");
579
.set("type", field_type)
580
.set("name", field_name)
581
.set("value", choice);
584
"for", item.one("input").generateID())
585
.setStyle("font-weight", "normal")
586
.set("text", choice);
591
* Remove a list of choices from the possible widget's choices.
593
* @method remove_choices
595
remove_choices: function(choices) {
598
this.fieldNode.all("select > option").each(
599
function(option) { options.push(option); });
601
"li input[value=" + choice + "]").each(
603
li_input.get('parentNode').remove();
609
Y.lazr.anim.green_flash({node: this.fieldNode}).run();
612
_sorted_position: function(choice) {
614
this.fieldNode.all("input").each(
616
options.push(node.get('value'));
619
options.push(choice);
620
return options.sort().indexOf(choice);
624
* Add new choices (if they are not already present).
626
* @method add_choices
628
add_choices: function(new_choices) {
631
if (this.fieldNode.all(
632
"li > input[value=" + choice + "]").isEmpty()) {
633
var list = this.fieldNode.one('ul');
635
list = Y.Node.create("<ul />");
636
this.fieldNode.empty().append(list);
638
var option = this._createChoice(choice);
639
var options = list.all('input');
640
if (options.isEmpty()) {
644
var pos = this._sorted_position(choice);
646
list.prepend(option);
649
list.insertBefore(option, options.item(pos));
655
Y.lazr.anim.green_flash({node: this.fieldNode}).run();
661
namespace.ChoiceListWidget = ChoiceListWidget;
665
322
* A special form of ChoiceListWidget for choosing architecture tags.
667
324
* @class ArchitecturesChoiceListWidget
790
* A special form of FormRowWidget, containing a select control.
792
* @class SelectWidget
796
SelectWidget = function() {
797
SelectWidget.superclass.constructor.apply(this, arguments);
800
Y.mix(SelectWidget, {
802
NAME: 'selectWidget',
807
* An array of objects from which to choose. Each object
808
* should contain a value for "value", "text" and "data".
814
/* I think this is a YUI3 wart; I can't see any way to
815
map() over a NodeList, so I must push the elements
816
one by one into an array first. */
817
var options = Y.Array([]);
818
this.fieldNode.all("select > option").each(
819
function(option) { options.push(option); });
823
value: option.get("value"),
824
text: option.get("text"),
825
data: option.getData("data")
830
setter: function(value, name) {
831
var select = Y.Node.create("<select />");
832
select.set("name", this.get("name"))
833
.set("size", this.get("size"));
834
if (this.get("multiple")) {
835
select.set("multiple", "multiple");
837
var choices = Y.Array(value);
840
var option = Y.Node.create("<option />");
841
option.set("value", choice.value)
842
.set("text", choice.text)
843
.setData("data", choice.data);
844
select.append(option);
847
if (choices.length > 0) {
848
this.fieldNode.empty().append(select);
851
this.fieldNode.empty();
857
* The current selection.
862
setter: function(value, name) {
863
if (!Y.Lang.isArray(value)) {
866
this.fieldNode.all("select > option").each(
870
value.indexOf(node.get("value")) >= 0);
876
this.fieldNode.all("select > option").each(
878
if (node.get("selected")) {
879
choice.push(node.get("value"));
888
* The number of rows to show in the select widget.
894
setter: function(value, name) {
895
this.fieldNode.all("select").set("size", value);
900
* Whether multiple rows can be selected.
906
setter: function(value, name) {
907
value = value ? true : false;
908
this.fieldNode.all("select").set("multiple", value);
917
Y.extend(SelectWidget, FormRowWidget, {
919
_sorted_position: function(choice) {
921
this.fieldNode.all("option").each(
923
options.push(node.get('text'));
926
options.push(choice);
927
return options.sort().indexOf(choice);
931
* Choose a size for the select control based on the number of
932
* choices, up to an optional maximum size.
936
autoSize: function(maxSize) {
937
var choiceCount = this.fieldNode.all("select > option").size();
938
if (choiceCount === 0) {
941
else if (maxSize === undefined) {
942
this.set("size", choiceCount);
944
else if (choiceCount < maxSize) {
945
this.set("size", choiceCount);
948
this.set("size", maxSize);
955
namespace.SelectWidget = SelectWidget;
959
447
* A special form of SelectWidget for choosing packagesets.
961
449
* @class PackagesetPickerWidget
1152
640
namespace.PackagesetPickerWidget = PackagesetPickerWidget;
1156
* A widget to encapsulate functionality around the form actions.
1158
* @class FormActionsWidget
1160
var FormActionsWidget;
1162
FormActionsWidget = function() {
1164
.superclass.constructor.apply(this, arguments);
1167
FormActionsWidget.ATTRS = {
1182
Y.mix(FormActionsWidget, {
1184
NAME: 'formActionsWidget',
1187
submitButtonNode: "input[type=submit]"
1192
Y.extend(FormActionsWidget, Y.Widget, {
1194
initializer: function(config) {
1195
this.client = new Y.lp.client.Launchpad();
1196
this.error_handler = new Y.lp.client.ErrorHandler();
1197
this.error_handler.clearProgressUI = Y.bind(this.hideSpinner, this);
1198
this.error_handler.showError = Y.bind(this.showError, this);
1199
this.submitButtonNode = config.submitButtonNode;
1200
this.spinnerNode = Y.Node.create(
1201
'<img src="/@@/spinner" alt="Loading..." />');
1205
* Show the spinner, and hide the submit button.
1207
* @method showSpinner
1209
showSpinner: function() {
1210
this.submitButtonNode.replace(this.spinnerNode);
1214
* Hide the spinner, and show the submit button again.
1216
* @method hideSpinner
1218
hideSpinner: function() {
1219
this.spinnerNode.replace(this.submitButtonNode);
1227
showError: function(error) {
1228
Y.Node.create('<p class="error message" />')
1229
.appendTo(this.get("contentBox"))
1230
.set("text", error);
1234
* Remove all errors that have been previously displayed by showError.
1236
* @method hideErrors
1238
hideErrors: function(error) {
1239
this.get("contentBox").all("p.error.message").remove();
1244
namespace.FormActionsWidget = FormActionsWidget;
1246
}, "0.1", {"requires": ["node", "dom", "io", "widget", "lp.client",
1247
"lazr.anim", "array-extras", "transition"]});
643
}, "0.1", {"requires": [
644
"node", "dom", "io", "widget", "lp.client",
645
"lp.app.formwidgets", "lazr.anim", "array-extras",