~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/code/javascript/requestbuild_overlay.js

[r=abentley][bug=824435][incr] Remove Javascript alert and add test
        for requestdailybuild.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
    }
59
59
};
60
60
 
 
61
namespace.RequestResponseHandler = RequestResponseHandler;
 
62
 
61
63
namespace.connect_requestbuilds = function() {
62
64
 
63
65
    var request_build_handle = Y.one('#request-builds');
132
134
var ONE_BUILD_MESSAGE = "1 new recipe build has been queued.";
133
135
var MANY_BUILDS_MESSAGE = "{nr_new} new recipe builds have been queued.";
134
136
 
135
 
namespace.connect_requestdailybuild = function() {
 
137
namespace.connect_requestdailybuild = function(config) {
136
138
 
137
139
    var request_daily_build_handle = Y.one('#request-daily-build');
 
140
    var display_message = function (message, css_class){
 
141
        var build_message_node = Y.Node.create('<div></div>')
 
142
            .set('id', 'new-builds-info')
 
143
            .addClass(css_class)
 
144
            .set('text', message)
 
145
            .append(Y.Node.create('<br />'))
 
146
            .append(Y.Node.create('<a></a>')
 
147
                .set('href', '#')
 
148
                .addClass('discreet')
 
149
                .addClass('js-action')
 
150
                .set('text', 'Dismiss'));
 
151
        build_message_node.one('a').on('click', function(e) {
 
152
            e.preventDefault();
 
153
            build_message_node.hide();
 
154
            if (css_class === 'build-error') {
 
155
                request_daily_build_handle.removeClass("unseen");
 
156
            }
 
157
        });
 
158
        request_daily_build_handle.insert(
 
159
                build_message_node,
 
160
                request_daily_build_handle);
 
161
            
 
162
    };
138
163
    request_daily_build_handle.on('click', function(e) {
139
164
        e.preventDefault();
140
165
 
154
179
            on: {
155
180
                failure: request_daily_build_response_handler.getErrorHandler(
156
181
                    function(handler, id, response) {
157
 
                        request_daily_build_handle.removeClass("unseen");
158
182
                        var server_error = 'Server error, ' +
159
183
                                           'please contact an administrator.';
160
184
                        handler.showError(server_error, null);
178
202
                                                MANY_BUILDS_MESSAGE,
179
203
                                                {nr_new: nr_new});
180
204
                        }
181
 
                        var build_message_node = Y.Node.create([
182
 
                            '<div id="new-builds-info" ' +
183
 
                                    'class="build-informational">',
184
 
                            new_builds_message,
185
 
                            '</div>'].join(''));
186
 
                        request_daily_build_handle.insert(
187
 
                                build_message_node,
188
 
                                request_daily_build_handle);
189
 
                        Y.later(20000, build_message_node, 'hide', true);
 
205
                        display_message(
 
206
                            new_builds_message, 'build-informational');
190
207
                    }
191
208
                  )
192
209
            },
193
210
            data: qs
194
211
        };
195
 
        Y.io(submit_url, y_config);
 
212
        var io = Y.io;
 
213
        if ( config !== undefined && Y.Lang.isValue(config.io)) {
 
214
            io = config.io;
 
215
        }
 
216
        io(submit_url, y_config);
196
217
    });
197
218
 
198
219
    // Wire up the processing hooks
204
225
        var error_msg = header;
205
226
        if (error != null)
206
227
            error_msg += " " + error;
207
 
        alert(error_msg);
 
228
        display_message(error_msg, 'build-error');
208
229
        Y.log(error_msg);
209
230
    };
210
231
};