11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
1 |
/* Copyright 2010 Canonical Ltd. This software is licensed under the
|
2 |
* GNU Affero General Public License version 3 (see the file LICENSE).
|
|
3 |
*
|
|
4 |
* A bugtracker form overlay that can create a bugtracker within any page.
|
|
5 |
*
|
|
11009.1.2
by Edwin Grubbs
Made formoverlay appear correctly with textareas that are wider than normal. |
6 |
* @namespace Y.lp.bugs.bugtracker_overlay
|
13588.9.2
by Gavin Panella
Rename lazr.anim to lp.anim. |
7 |
* @requires dom, node, io-base, lp.anim, lazr.formoverlay
|
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
8 |
*/
|
9 |
YUI.add('lp.bugs.bugtracker_overlay', function(Y) { |
|
11009.1.2
by Edwin Grubbs
Made formoverlay appear correctly with textareas that are wider than normal. |
10 |
Y.log('loading lp.bugs.bugtracker_overlay'); |
11 |
var namespace = Y.namespace('lp.bugs.bugtracker_overlay'); |
|
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
12 |
|
13 |
var bugtracker_form; |
|
14 |
var next_step; |
|
15 |
||
16 |
var save_new_bugtracker = function(data) { |
|
17 |
||
18 |
var parameters = { |
|
11009.1.5
by Edwin Grubbs
Re-ordered the fields in the form. Successfully call ensureBugTracker() from FormOverlay widget. |
19 |
bug_tracker_type: data['field.bugtrackertype'][0], |
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
20 |
name: data['field.name'][0].toLowerCase(), |
11009.1.5
by Edwin Grubbs
Re-ordered the fields in the form. Successfully call ensureBugTracker() from FormOverlay widget. |
21 |
title: data['field.title'][0], |
22 |
base_url: data['field.baseurl'][0], |
|
23 |
summary: data['field.summary'][0], |
|
24 |
contact_details: data['field.contactdetails'][0] |
|
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
25 |
};
|
26 |
||
11009.1.5
by Edwin Grubbs
Re-ordered the fields in the form. Successfully call ensureBugTracker() from FormOverlay widget. |
27 |
var finish_new_bugtracker = function(entry) { |
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
28 |
bugtracker_form.clearError(); |
29 |
bugtracker_form.hide(); |
|
30 |
// Reset the HTML form inside the widget.
|
|
31 |
bugtracker_form.get('contentBox').one('form').reset(); |
|
11009.1.7
by Edwin Grubbs
Cleaned up display. |
32 |
next_step(entry); |
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
33 |
};
|
34 |
||
12421.1.12
by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client. |
35 |
var client = new Y.lp.client.Launchpad(); |
11009.1.5
by Edwin Grubbs
Re-ordered the fields in the form. Successfully call ensureBugTracker() from FormOverlay widget. |
36 |
client.named_post('/bugs/bugtrackers', 'ensureBugTracker', { |
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
37 |
parameters: parameters, |
38 |
on: { |
|
39 |
success: finish_new_bugtracker, |
|
40 |
failure: function (ignore, response, args) { |
|
41 |
var error_box = Y.one('#bugtracker-error'); |
|
11009.1.5
by Edwin Grubbs
Re-ordered the fields in the form. Successfully call ensureBugTracker() from FormOverlay widget. |
42 |
var error_message = response.statusText + '\n\n' + |
43 |
response.responseText; |
|
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
44 |
bugtracker_form.showError(error_message); |
11009.1.7
by Edwin Grubbs
Cleaned up display. |
45 |
// XXX EdwinGrubbs 2007-06-18 bug=596025
|
46 |
// This should be done by FormOverlay.showError().
|
|
11009.1.5
by Edwin Grubbs
Re-ordered the fields in the form. Successfully call ensureBugTracker() from FormOverlay widget. |
47 |
bugtracker_form.error_node.scrollIntoView(); |
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
48 |
}
|
49 |
}
|
|
50 |
});
|
|
51 |
};
|
|
52 |
||
53 |
||
54 |
var setup_bugtracker_form = function () { |
|
55 |
var form_submit_button = Y.Node.create( |
|
56 |
'<input type="submit" name="field.actions.register" ' + |
|
11009.1.7
by Edwin Grubbs
Cleaned up display. |
57 |
'id="formoverlay-add-bugtracker" value="Create bug tracker"/>'); |
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
58 |
bugtracker_form = new Y.lazr.FormOverlay({ |
11009.1.7
by Edwin Grubbs
Cleaned up display. |
59 |
headerContent: '<h2>Create Bug Tracker</h2>', |
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
60 |
form_submit_button: form_submit_button, |
61 |
centered: true, |
|
62 |
form_submit_callback: save_new_bugtracker, |
|
63 |
visible: false |
|
64 |
});
|
|
65 |
bugtracker_form.loadFormContentAndRender( |
|
11009.1.2
by Edwin Grubbs
Made formoverlay appear correctly with textareas that are wider than normal. |
66 |
'/bugs/bugtrackers/+newbugtracker/++form++'); |
11009.1.7
by Edwin Grubbs
Cleaned up display. |
67 |
// XXX EdwinGrubbs 2010-06-18 bug=596130
|
68 |
// render() and show() will actually be called before the
|
|
69 |
// asynchronous io call finishes, so the widget appears first
|
|
70 |
// without any content. However, this is better than loading the
|
|
71 |
// form every time the page loads despite the form overlay being
|
|
72 |
// used rarely.
|
|
11009.1.5
by Edwin Grubbs
Re-ordered the fields in the form. Successfully call ensureBugTracker() from FormOverlay widget. |
73 |
bugtracker_form.render(); |
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
74 |
bugtracker_form.show(); |
75 |
};
|
|
76 |
||
11009.1.2
by Edwin Grubbs
Made formoverlay appear correctly with textareas that are wider than normal. |
77 |
var show_bugtracker_form = function(e) { |
78 |
e.preventDefault(); |
|
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
79 |
if (bugtracker_form) { |
80 |
bugtracker_form.show(); |
|
81 |
} else { |
|
82 |
// This function call is asynchronous, so we can move
|
|
83 |
// bugtracker_form.show() below it.
|
|
84 |
setup_bugtracker_form(); |
|
85 |
}
|
|
11009.1.7
by Edwin Grubbs
Cleaned up display. |
86 |
|
87 |
// XXX EdwinGrubbs 2010-06-18 bug=596113
|
|
88 |
// FormOverlay calls centered(), which can cause this tall form
|
|
89 |
// to be position where the top of the form is no longer
|
|
90 |
// accessible.
|
|
91 |
var bounding_box = bugtracker_form.get('boundingBox'); |
|
92 |
var min_top = 10; |
|
93 |
if (bounding_box.get('offsetTop') < min_top) { |
|
94 |
bounding_box.setStyle('top', min_top + 'px'); |
|
95 |
}
|
|
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
96 |
};
|
97 |
||
98 |
/**
|
|
99 |
* Attaches a bugtracker form overlay widget to an element.
|
|
100 |
*
|
|
101 |
* @method attach_widget
|
|
102 |
* @param {Object} config Object literal of config name/value pairs.
|
|
103 |
* activate_node is the node that shows the form
|
|
104 |
* when it is clicked.
|
|
105 |
* next_step is the function to be called after
|
|
106 |
* the bugtracker is created.
|
|
107 |
*/
|
|
11009.1.2
by Edwin Grubbs
Made formoverlay appear correctly with textareas that are wider than normal. |
108 |
namespace.attach_widget = function(config) { |
109 |
Y.log('lp.bugs.bugtracker_overlay.attach_widget()'); |
|
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
110 |
if (Y.UA.ie) { |
111 |
return; |
|
112 |
}
|
|
113 |
if (config === undefined) { |
|
114 |
throw new Error( |
|
115 |
"Missing attach_widget config for bugtracker_overlay."); |
|
116 |
}
|
|
117 |
if (config.activate_node === undefined || |
|
118 |
config.next_step === undefined) { |
|
119 |
throw new Error( |
|
120 |
"attach_widget config for bugtracker_overlay has " + |
|
121 |
"undefined properties."); |
|
122 |
}
|
|
123 |
next_step = config.next_step; |
|
11009.1.2
by Edwin Grubbs
Made formoverlay appear correctly with textareas that are wider than normal. |
124 |
Y.log('lp.bugs.bugtracker_overlay.attach_widget() setup onclick'); |
125 |
config.activate_node.addClass('js-action'); |
|
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
126 |
config.activate_node.on('click', show_bugtracker_form); |
127 |
};
|
|
128 |
||
13588.9.2
by Gavin Panella
Rename lazr.anim to lp.anim. |
129 |
}, "0.1", {"requires": ["dom", "node", "io-base", "lp.anim", |
12421.1.12
by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client. |
130 |
"lazr.formoverlay", "lp.app.calendar", "lp.client" |
11009.1.1
by Edwin Grubbs
BugTrackerPickerWidget partially working. |
131 |
]});
|