~ubuntu-branches/ubuntu/raring/maas/raring-updates

« back to all changes in this revision

Viewing changes to src/maasserver/static/jslibs/yui/3.4.1/build/io-upload-iframe/io-upload-iframe-debug.js

  • Committer: Package Import Robot
  • Author(s): Andres Rodriguez
  • Date: 2012-07-03 17:42:37 UTC
  • mfrom: (1.1.13)
  • Revision ID: package-import@ubuntu.com-20120703174237-p8l0keuuznfg721k
Tags: 0.1+bzr709+dfsg-0ubuntu1
* New Upstream release
* debian/control:
  - Depends on python-celery, python-tempita, libjs-yui3-{full,min},
    libjs-raphael
* debian/maas.install:
  - Install apiclient, celeryconfig.py, maas-import-pxe-files, preseeds_v2.
  - Update to install various files from chroot, rather tha manually copy
    them from the source.
* debian/maas.links: symlink celeryconfig.py
* debian/maas.maas-celery.upstart: Add job.
* debian/rules:
  - Install celery upstart job.
  - Do not install jslibs as packages are now used.
  - Drop copying of maas_local_settings_sample.py as source now ships
    a maas_local_settings.py
* debian/patches:
  - 04-maas-http-fix.patch: Drop. Merged upstream.
  - 01-fix-database-settings.patch: Refreshed.
  - 99_enums_js.patch: Added until creation of enum.js / build process
    is fixed.
* debian/maas.postinst: Update bzr version to correctly handle upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
YUI 3.4.1 (build 4118)
3
 
Copyright 2011 Yahoo! Inc. All rights reserved.
4
 
Licensed under the BSD License.
5
 
http://yuilibrary.com/license/
6
 
*/
7
 
YUI.add('io-upload-iframe', function(Y) {
8
 
 
9
 
/**
10
 
Extends the IO  to enable file uploads, with HTML forms 
11
 
using an iframe as the transport medium.
12
 
@module io-base
13
 
@submodule io-upload-iframe
14
 
@for IO
15
 
**/
16
 
 
17
 
var w = Y.config.win,
18
 
    d = Y.config.doc,
19
 
    _std = (d.documentMode && d.documentMode >= 8),
20
 
    _d = decodeURIComponent;
21
 
 
22
 
/**
23
 
 * Creates the iframe transported used in file upload
24
 
 * transactions, and binds the response event handler.
25
 
 *
26
 
 * @method _cFrame
27
 
 * @private
28
 
 * @param {Object} o Transaction object generated by _create().
29
 
 * @param {Object} c Configuration object passed to YUI.io().
30
 
 * @param {Object} io
31
 
 */
32
 
function _cFrame(o, c, io) {
33
 
    var i = Y.Node.create('<iframe id="io_iframe' + o.id + '" name="io_iframe' + o.id + '" />');
34
 
        i._node.style.position = 'absolute';
35
 
        i._node.style.top = '-1000px';
36
 
        i._node.style.left = '-1000px';
37
 
        Y.one('body').appendChild(i);
38
 
    // Bind the onload handler to the iframe to detect the file upload response.
39
 
    Y.on("load", function() { io._uploadComplete(o, c); }, '#io_iframe' + o.id);
40
 
}
41
 
 
42
 
/**
43
 
 * Removes the iframe transport used in the file upload 
44
 
 * transaction.
45
 
 *
46
 
 * @method _dFrame
47
 
 * @private
48
 
 * @param {Number} id The transaction ID used in the iframe's creation.
49
 
 */
50
 
function _dFrame(id) {
51
 
        Y.Event.purgeElement('#io_iframe' + id, false);
52
 
        Y.one('body').removeChild(Y.one('#io_iframe' + id));
53
 
        Y.log('The iframe transport for transaction ' + id + ' has been destroyed.', 'info', 'io');
54
 
}
55
 
 
56
 
Y.mix(Y.IO.prototype, {
57
 
   /**
58
 
    * Parses the POST data object and creates hidden form elements
59
 
    * for each key-value, and appends them to the HTML form object.
60
 
    * @method appendData
61
 
    * @private
62
 
    * @static
63
 
    * @param {Object} f HTML form object.
64
 
    * @param {String} s The key-value POST data.
65
 
    * @return {Array} e Array of created fields.
66
 
    */
67
 
    _addData: function(f, s) {
68
 
        // Serialize an object into a key-value string using
69
 
        // querystring-stringify-simple.
70
 
        if (Y.Lang.isObject(s)) {
71
 
            s = Y.QueryString.stringify(s);
72
 
        }
73
 
 
74
 
        var o = [],
75
 
            m = s.split('='),
76
 
            i, l;
77
 
 
78
 
        for (i = 0, l = m.length - 1; i < l; i++) {
79
 
            o[i] = d.createElement('input');
80
 
            o[i].type = 'hidden';
81
 
            o[i].name = _d(m[i].substring(m[i].lastIndexOf('&') + 1));
82
 
            o[i].value = (i + 1 === l) ? _d(m[i + 1]) : _d(m[i + 1].substring(0, (m[i + 1].lastIndexOf('&'))));
83
 
            f.appendChild(o[i]);
84
 
            Y.log('key: ' +  o[i].name + ' and value: ' + o[i].value + ' added as form data.', 'info', 'io');
85
 
        }
86
 
 
87
 
        return o;
88
 
    },
89
 
 
90
 
   /**
91
 
    * Removes the custom fields created to pass additional POST
92
 
    * data, along with the HTML form fields.
93
 
    * @method _removeData
94
 
    * @private
95
 
    * @static
96
 
    * @param {Object} f HTML form object.
97
 
    * @param {Object} o HTML form fields created from configuration.data.
98
 
    */
99
 
    _removeData: function(f, o) {
100
 
        var i, l;
101
 
 
102
 
        for (i = 0, l = o.length; i < l; i++) {
103
 
            f.removeChild(o[i]);
104
 
        }
105
 
    },
106
 
 
107
 
   /**
108
 
    * Sets the appropriate attributes and values to the HTML
109
 
    * form, in preparation of a file upload transaction.
110
 
    * @method _setAttrs
111
 
    * @private
112
 
    * @static
113
 
    * @param {Object} f HTML form object.
114
 
    * @param {Object} id The Transaction ID.
115
 
    * @param {Object} uri Qualified path to transaction resource.
116
 
    */
117
 
    _setAttrs: function(f, id, uri) {
118
 
        f.setAttribute('action', uri);
119
 
        f.setAttribute('method', 'POST');
120
 
        f.setAttribute('target', 'io_iframe' + id );
121
 
        f.setAttribute(Y.UA.ie && !_std ? 'encoding' : 'enctype', 'multipart/form-data');
122
 
    },
123
 
 
124
 
   /**
125
 
    * Reset the HTML form attributes to their original values.
126
 
    * @method _resetAttrs
127
 
    * @private
128
 
    * @static
129
 
    * @param {Object} f HTML form object.
130
 
    * @param {Object} a Object of original attributes.
131
 
    */
132
 
    _resetAttrs: function(f, a) {
133
 
        Y.Object.each(a, function(v, p) {
134
 
            if (v) {
135
 
                f.setAttribute(p, v);
136
 
            }
137
 
            else {
138
 
                f.removeAttribute(p);
139
 
            }
140
 
        });
141
 
    },
142
 
 
143
 
   /**
144
 
    * Starts timeout count if the configuration object
145
 
    * has a defined timeout property.
146
 
    *
147
 
    * @method _startTimeout
148
 
    * @private
149
 
    * @static
150
 
    * @param {Object} o Transaction object generated by _create().
151
 
    * @param {Object} c Configuration object passed to YUI.io().
152
 
    */
153
 
    _startTimeout: function(o, c) {
154
 
        var io = this;
155
 
 
156
 
        io._timeout[o.id] = w.setTimeout(
157
 
            function() {
158
 
                o.status = 0;
159
 
                o.statusText = 'timeout';
160
 
                io.complete(o, c);
161
 
                io.end(o, c);
162
 
                Y.log('Transaction ' + o.id + ' timeout.', 'info', 'io');
163
 
            }, c.timeout);
164
 
    },
165
 
 
166
 
   /**
167
 
    * Clears the timeout interval started by _startTimeout().
168
 
    * @method _clearTimeout
169
 
    * @private
170
 
    * @static
171
 
    * @param {Number} id - Transaction ID.
172
 
    */
173
 
    _clearTimeout: function(id) {
174
 
        var io = this;
175
 
 
176
 
        w.clearTimeout(io._timeout[id]);
177
 
        delete io._timeout[id];
178
 
    },
179
 
 
180
 
   /**
181
 
    * Bound to the iframe's Load event and processes
182
 
    * the response data.
183
 
    * @method _uploadComplete
184
 
    * @private
185
 
    * @static
186
 
    * @param {Object} o The transaction object
187
 
    * @param {Object} c Configuration object for the transaction.
188
 
    */
189
 
    _uploadComplete: function(o, c) {
190
 
        var io = this,
191
 
            d = Y.one('#io_iframe' + o.id).get('contentWindow.document'),
192
 
            b = d.one('body'),
193
 
            p;
194
 
 
195
 
        if (c.timeout) {
196
 
            io._clearTimeout(o.id);
197
 
        }
198
 
 
199
 
                try {
200
 
                        if (b) {
201
 
                                // When a response Content-Type of "text/plain" is used, Firefox and Safari
202
 
                                // will wrap the response string with <pre></pre>.
203
 
                                p = b.one('pre:first-child');
204
 
                                o.c.responseText = p ? p.get('text') : b.get('text');
205
 
                                Y.log('The responseText value for transaction ' + o.id + ' is: ' + o.c.responseText + '.', 'info', 'io');
206
 
                        }
207
 
                        else {
208
 
                                o.c.responseXML = d._node;
209
 
                                Y.log('The response for transaction ' + o.id + ' is an XML document.', 'info', 'io');
210
 
                        }
211
 
                }
212
 
                catch (e) {
213
 
                        o.e = "upload failure";
214
 
                }
215
 
 
216
 
        io.complete(o, c);
217
 
        io.end(o, c);
218
 
        // The transaction is complete, so call _dFrame to remove
219
 
        // the event listener bound to the iframe transport, and then
220
 
        // destroy the iframe.
221
 
        w.setTimeout( function() { _dFrame(o.id); }, 0);
222
 
    },
223
 
 
224
 
   /**
225
 
    * Uploads HTML form data, inclusive of files/attachments,
226
 
    * using the iframe created in _create to facilitate the transaction.
227
 
    * @method _upload
228
 
    * @private
229
 
    * @static
230
 
    * @param {Object} o The transaction object
231
 
    * @param {Object} uri Qualified path to transaction resource.
232
 
    * @param {Object} c Configuration object for the transaction.
233
 
    */
234
 
    _upload: function(o, uri, c) {
235
 
        var io = this,
236
 
            f = (typeof c.form.id === 'string') ? d.getElementById(c.form.id) : c.form.id,
237
 
            // Track original HTML form attribute values.
238
 
            attr = {
239
 
                action: f.getAttribute('action'),
240
 
                target: f.getAttribute('target')
241
 
            },
242
 
            fields;
243
 
 
244
 
        // Initialize the HTML form properties in case they are
245
 
        // not defined in the HTML form.
246
 
        io._setAttrs(f, o.id, uri);
247
 
        if (c.data) {
248
 
            fields = io._addData(f, c.data);
249
 
        }
250
 
 
251
 
        // Start polling if a callback is present and the timeout
252
 
        // property has been defined.
253
 
        if (c.timeout) {
254
 
            io._startTimeout(o, c);
255
 
            Y.log('Transaction timeout started for transaction ' + o.id + '.', 'info', 'io');
256
 
        }
257
 
 
258
 
        // Start file upload.
259
 
        f.submit();
260
 
        io.start(o, c);
261
 
        if (c.data) {
262
 
            io._removeData(f, fields);
263
 
        }
264
 
        // Restore HTML form attributes to their original values.
265
 
        io._resetAttrs(f, attr);
266
 
 
267
 
        return {
268
 
            id: o.id,
269
 
            abort: function() {
270
 
                o.status = 0;
271
 
                o.statusText = 'abort';
272
 
                if (Y.one('#io_iframe' + o.id)) {
273
 
                    _dFrame(o.id);
274
 
                    io.complete(o, c);
275
 
                    io.end(o, c);
276
 
                    Y.log('Transaction ' + o.id + ' aborted.', 'info', 'io');
277
 
                }
278
 
                else {
279
 
                    Y.log('Attempted to abort transaction ' + o.id + ' but transaction has completed.', 'warn', 'io');
280
 
                    return false;
281
 
                }
282
 
            },
283
 
            isInProgress: function() {
284
 
                return Y.one('#io_iframe' + o.id) ? true : false;
285
 
            },
286
 
            io: io
287
 
        };
288
 
    },
289
 
 
290
 
    upload: function(o, uri, c) {
291
 
        _cFrame(o, c, this);
292
 
        return this._upload(o, uri, c);
293
 
    }
294
 
});
295
 
 
296
 
 
297
 
 
298
 
}, '3.4.1' ,{requires:['io-base','node-base']});