1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
/* Copyright 2011 Canonical Ltd. This software is licensed under the
* GNU Affero General Public License version 3 (see the file LICENSE).
*
* @namespace Y.lp.app.widgets
* @requires Y.lazr.picker
*/
YUI.add('lp.app.widgets', function(Y) {
var namespace = Y.namespace('lp.app.widgets');
/**
* Extend the lazr-js Picker.
*/
var Picker = function() {
Picker.superclass.constructor.apply(this, arguments);
};
Y.extend(Picker, Y.lazr.Picker, {
// We want to render alt title slightly differently.
_renderTitleUI: function(data) {
var li_title = Y.Node.create(
'<span></span>').addClass(Y.lazr.Picker.C_RESULT_TITLE);
if (data.title === undefined) {
// Display an empty element if data is empty.
return li_title;
}
var title = this._text_or_link(
data.title, data.title_link, data.link_css);
li_title.appendChild(title);
if (data.alt_title) {
var alt_link = null;
if (data.alt_title_link) {
alt_link =Y.Node.create('<a></a>')
.addClass(data.link_css)
.addClass('discreet');
alt_link.set('text', " Details...")
.set('href', data.alt_title_link);
Y.on('click', function(e) {
e.halt();
window.open(data.alt_title_link);
}, alt_link);
}
li_title.appendChild(' (');
li_title.appendChild(document.createTextNode(data.alt_title));
li_title.appendChild(')');
if (alt_link !== null) {
li_title.appendChild(alt_link);
}
}
return li_title;
}
});
Picker.NAME = 'picker';
namespace.Picker = Picker;
/*
* Extend the picker into the PersonPicker
*/
var footer_label = ".yui3-picker-footer-slot";
var PersonPicker = function() {
PersonPicker.superclass.constructor.apply(this, arguments);
this._extra_buttons = Y.Node.create('<div class="extra-form-buttons"/>');
};
Y.extend(PersonPicker, namespace.Picker, {
initializer: function(cfg) {
PersonPicker.superclass.initializer.apply(this, arguments);
var show_assign_me_button = true;
var show_remove_button = true;
if (cfg !== undefined) {
if (cfg.show_assign_me_button !== undefined) {
show_assign_me_button = cfg.show_assign_me_button;
}
if (cfg.show_remove_button !== undefined) {
show_remove_button = cfg.show_remove_button;
}
}
this._show_assign_me_button = show_assign_me_button;
this._show_remove_button = show_remove_button;
},
hide: function() {
this.get('boundingBox').setStyle('display', 'none');
},
show: function() {
this.get('boundingBox').setStyle('display', 'block');
},
remove: function () {
this.fire('save', {value: ''});
},
assign_me: function () {
name = LP.links.me.replace('/~', '');
this.fire('save', {value: name});
},
renderUI: function() {
this.constructor.superclass.renderUI.call(this);
var remove_button, assign_me_button;
var remove_button_text = "Remove assignee";
var assign_me_button_text = "Assign me";
if (this._show_remove_button) {
remove_button = Y.Node.create(
'<a class="yui-picker-remove-button bg-image" ' +
'href="javascript:void(0)" ' +
'style="background-image: url(/@@/remove); padding-right: ' +
'1em">' + remove_button_text + '</a>');
remove_button.on('click', this.remove, this);
this._extra_buttons.appendChild(remove_button);
this.remove_button = remove_button;
}
if (this._show_assign_me_button) {
assign_me_button = Y.Node.create(
'<a class="yui-picker-assign-me-button bg-image" ' +
'href="javascript:void(0)" ' +
'style="background-image: url(/@@/person)">' +
assign_me_button_text + '</a>');
assign_me_button.on('click', this.assign_me, this);
this._extra_buttons.appendChild(assign_me_button);
this.assign_me_button = assign_me_button;
}
},
syncUI: function() {
// call Picker's sync
this.constructor.superclass.syncUI.call(this);
footer_slot = Y.one(footer_label);
footer_slot.appendChild(this._extra_buttons);
}
});
PersonPicker.NAME = 'person-picker';
namespace.PersonPicker = PersonPicker;
}, "0.1", {"requires": ["lazr.picker"]});
|