18
18
* @param {String} attribute_name The attribute on the resource being
20
20
* @param {String} content_box_id
21
* @param {Object} config Object literal of config name/value pairs.
21
* @param {Object} config Object literal of config name/value pairs. The
22
* values listed below are common for all picker types.
23
* config.picker_type: the type of picker to create (default or person).
22
24
* config.header: a line of text at the top of the widget.
23
25
* config.step_title: overrides the subtitle.
24
26
* config.null_display_value: Override the default 'None' text.
25
* config.show_remove_button: Should the remove button be shown?
26
* Defaults to false, should be a boolean.
27
* config.show_assign_me_button: Should the 'assign me' button be shown?
28
* Defaults to false, should be a boolean.
29
27
* config.show_search_box: Should the search box be shown.
30
28
* Vocabularies that are not huge should not have a search box.
48
44
if (config.null_display_value !== undefined) {
49
45
null_display_value = config.null_display_value;
52
if (config.show_remove_button !== undefined) {
53
show_remove_button = config.show_remove_button;
56
if (config.show_assign_me_button !== undefined) {
57
show_assign_me_button = config.show_assign_me_button;
60
47
if (config.show_search_box !== undefined) {
61
48
show_search_box = config.show_search_box;
63
if (config.picker_type === undefined &&
64
(show_assign_me_button || show_remove_button)) {
65
config.picker_type = 'person';
69
52
var content_box = Y.one('#' + content_box_id);
82
var update_button_text = function() {
83
var link_text = picker._remove_person_text;
84
if (picker.get('selected_value_metadata') === 'team') {
85
link_text = picker._remove_team_text;
87
remove_button.set('text', link_text);
90
var show_hide_buttons = function () {
91
var link = content_box.one('.yui3-activator-data-box a');
93
if (link === null || !show_remove_button) {
94
remove_button.addClass('yui3-picker-hidden');
96
remove_button.removeClass('yui3-picker-hidden');
101
if (assign_me_button) {
103
&& link.get('href').match(LP.links.me + "$") == LP.links.me) {
104
assign_me_button.addClass('yui3-picker-hidden');
106
assign_me_button.removeClass('yui3-picker-hidden');
111
65
var save = function (picker_result) {
112
66
activator.renderProcessing();
113
67
var success_handler = function (entry) {
68
var to_render = null_display_value;
69
var selected_value = null;
70
if (entry.get(attribute_name) !== null) {
71
to_render = entry.getHTML(attribute_name);
72
selected_value = picker_result.api_uri;
74
// NB We need to set the selected_value_metadata attribute first
75
// because we listen for changes to selected_value.
114
76
picker.set('selected_value_metadata', picker_result.metadata);
115
activator.renderSuccess(entry.getHTML(attribute_name));
119
var patch_payload = {};
120
patch_payload[attribute_name] = Y.lp.client.get_absolute_uri(
121
picker_result.api_uri);
123
var client = new Y.lp.client.Launchpad();
124
client.patch(picker._resource_uri, patch_payload, {
125
accept: 'application/json;include=lp_html',
127
success: success_handler,
128
failure: failure_handler
133
// Create a new assign_me and remove_assignee function that uses the
134
// patcher save method instead of the standard picker save.
135
var assign_me = function () {
144
var remove = function () {
146
activator.renderProcessing();
147
var success_handler = function (entry) {
148
activator.renderSuccess(Y.Node.create(null_display_value));
152
var patch_payload = {};
153
patch_payload[attribute_name] = null;
155
var client = new Y.lp.client.Launchpad();
156
// Use picker._resource_uri, since it might have been changed
157
// from the outside after the widget has already been initialized.
77
picker.set('selected_value', selected_value);
78
activator.renderSuccess(to_render);
81
var patch_payload = {};
82
if (Y.Lang.isValue(picker_result.api_uri)) {
83
patch_payload[attribute_name] = Y.lp.client.get_absolute_uri(
84
picker_result.api_uri);
86
patch_payload[attribute_name] = null;
89
var client = new Y.lp.client.Launchpad();
158
90
client.patch(picker._resource_uri, patch_payload, {
159
91
accept: 'application/json;include=lp_html',
167
99
config.save = save;
168
100
var picker = namespace.create(vocabulary, config);
169
101
picker._resource_uri = resource_uri;
170
var remove_button = picker.remove_button;
171
var assign_me_button = picker.assign_me_button;
172
if (show_remove_button) {
173
Y.Event.purgeElement(remove_button);
174
remove_button.on('click', remove);
176
if (show_assign_me_button) {
177
Y.Event.purgeElement(assign_me_button);
178
assign_me_button.on('click', assign_me);
181
103
// If we are to pre-load the vocab, we need a spinner.
182
104
// We set it up here because we only want to do it once and the