~dbarth/unity-webapps-qml/temporary-trunk

« back to all changes in this revision

Viewing changes to src/Ubuntu/UnityWebApps/bindings/content-hub/client/content-hub.js

  • Committer: Tarmac
  • Author(s): Alexandre Abreu
  • Date: 2014-02-03 23:30:23 UTC
  • mfrom: (76.2.9 fix-content-hub-exports)
  • Revision ID: tarmac-20140203233023-z1yg781gv36tbqod
Fix content hub export.

Approved by PS Jenkins bot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
function createContentHubApi(backendBridge) {
2
2
    var PLUGIN_URI = 'ContentHub';
3
3
 
4
 
    function ContentTransfer(objectid) {
 
4
    function ContentTransfer(objectid, content) {
5
5
        this._proxy = backendBridge.createRemoteObject(
6
6
            PLUGIN_URI, 'ContentTransfer', objectid);
 
7
 
 
8
        this._store = content && content.store
 
9
             ? content.store : null;
 
10
        this._state = content && content.state
 
11
             ? content.state : null;
7
12
    };
8
13
    ContentTransfer.prototype = {
9
14
        // object methods
20
25
        // properties
21
26
 
22
27
        /**
 
28
         * Retrieves the current store.
 
29
         *
 
30
         * If the callback parameter is not set, the current "local" value is retrieved.
 
31
         *
 
32
         * @method store
 
33
         * @param callback (optional) {Function(String)}
 
34
         */
 
35
        store: function(callback) {
 
36
            if (callback && typeof(callback) === 'function') {
 
37
                this._proxy.call('store', [], callback);
 
38
                return;
 
39
            }
 
40
            return this._store;
 
41
        },
 
42
        /**
 
43
         * Sets the current store for the ContentTransfer.
 
44
         *
 
45
         * @method setStore
 
46
         * @param store {ContentStore}
 
47
         * @param callback (optional) {Function()}
 
48
         */
 
49
        setStore: function(store, callback) {
 
50
            this._proxy.call('setStore', [store.serialize(), callback]);
 
51
        },
 
52
 
 
53
        /**
 
54
         * Retrieves the current state.
 
55
         *
 
56
         * If the callback parameter is not set, the current "local" value is retrieved.
 
57
         *
 
58
         * @method state
 
59
         * @param callback (optional) {Function(ContentTransfer.State)}
 
60
         */
 
61
        state: function(callback) {
 
62
            if (callback && typeof(callback) === 'function') {
 
63
                this._proxy.call('state', [], callback);
 
64
                return;
 
65
            }
 
66
            return this._state;
 
67
        },
 
68
        /**
 
69
         * Sets the state of the transfer.
 
70
         *
 
71
         * @method setState
 
72
         * @param state {ContentTransfer.State}
 
73
         * @param callback {Function()} called when the state has been updated
 
74
         */
 
75
        setState: function(state, callback) {
 
76
            this._proxy.call('setState', [state, callback]);
 
77
        },
 
78
 
 
79
        /**
23
80
         * Retrieves the current selection type.
24
81
         *
25
82
         * @method selectionType
33
90
         *
34
91
         * @method setSelectionType
35
92
         * @param selectionType {ContentTransfer.SelectionType}
 
93
         * @param callback {Function()} called when the state has been updated
36
94
         */
37
 
        setSelectionType: function(selectionType) {
38
 
            this._proxy.call('setSelectionType', [selectionType]);
 
95
        setSelectionType: function(selectionType, callback) {
 
96
            this._proxy.call('setSelectionType', [selectionType, callback]);
39
97
        },
40
98
 
41
99
        /**
52
110
         *
53
111
         * @method setDirection
54
112
         * @param direction {ContentTransfer.Direction}
 
113
         * @param callback {Function()} called when the state has been updated
55
114
         */
56
 
        setDirection: function(direction) {
57
 
            this._proxy.call('setDirection', [direction]);
 
115
        setDirection: function(direction, callback) {
 
116
            this._proxy.call('setDirection', [direction, callback]);
58
117
        },
59
118
 
60
119
        /**
61
 
         * Retrieves the list of items included in the ContentTransfer.
 
120
         * Retrieves the list of items associated with the ContentTransfer.
62
121
         *
63
122
         * @method items
64
123
         * @param callback {Function( {Object{name: , url: }} )}
66
125
        items: function(callback) {
67
126
            this._proxy.call('items', [], callback);
68
127
        },
 
128
        /**
 
129
         * Sets the list of items for the associated ContentTransfer (used when exporting).
 
130
         *
 
131
         * @method setItems
 
132
         * @param items {Array of Object{name: String, url: String}}
 
133
         * @param callback {Function()} called when the state has been updated
 
134
         */
 
135
        setItems: function(items, callback) {
 
136
            this._proxy.call('setItems', [items, callback]);
 
137
        },
69
138
 
70
139
        // methods
71
140
 
201
270
         * @method uri
202
271
         * @param callback (optional) {Function(String)}
203
272
         */
204
 
        uri: function() {
 
273
        uri: function(callback) {
205
274
            if (callback && typeof(callback) === 'function') {
206
275
                this._proxy.call('uri', [], callback);
207
276
                return;
315
384
        },
316
385
 
317
386
        /**
 
387
         * Returns all possible peers for the given ContentType.
 
388
         *
 
389
         * @method knownSourcesForType
 
390
         * @param type {ContentType} Content type.
 
391
         * @param callback {Function ({ Array of {ContentPeer} })} Function called with the possible ContentPeers.
 
392
         */
 
393
        knownSourcesForType: function(type, callback) {
 
394
            backendBridge.call('ContentHub.knownSourcesForType',
 
395
                               [type],
 
396
                               function(peers) {
 
397
                                    var wrappedPeers = [];
 
398
 
 
399
                                   // FIXME: do this above recursively in the (bridge.js)
 
400
                                    for (var i = 0; i < peers.length; ++i) {
 
401
                                        wrappedPeers.push(
 
402
                                                    new ContentPeer(
 
403
                                                        peers[i].objectid,
 
404
                                                        peers[i].content));
 
405
                                    }
 
406
                                    callback (wrappedPeers);
 
407
                               });
 
408
        },
 
409
 
 
410
        /**
318
411
         * Creates a ContentStore object for the given content type.
319
412
         *
320
413
         * @method importContent
341
434
                               callback);
342
435
        },
343
436
 
 
437
        /**
 
438
         * Creates a ContentStore object for the given ContentPeer.
 
439
         *
 
440
         * @method importContent
 
441
         * @param callback {Function} function({ContentTransfer}) Function when one requests a resource to be exported.
 
442
         *                                                          The corresponding ContentTransfer is provided as a parameter.
 
443
         */
 
444
        onExportRequested: function(callback) {
 
445
            backendBridge.call('ContentHub.onExportRequested',
 
446
                               [callback]);
 
447
        },
344
448
 
345
449
        // Internal
346
450