File: imple.js

package info (click to toggle)
php-horde-core 2.27.6%2Bdebian1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,368 kB
  • ctags: 6,126
  • sloc: php: 26,083; xml: 4,239; sh: 18; makefile: 11
file content (56 lines) | stat: -rw-r--r-- 1,359 bytes parent folder | download | duplicates (4)
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
/**
 * imple.js - Horde core Imple code.
 *
 * Fires these events:
 * ===================
 * [IMPLE NAME]:do
 * Parameter: parameters list to send to the AJAX endpoint
 *
 * [IMPLE NAME]:complete
 * Parameter: response from AJAX endpoint
 *
 * @author     Michael Slusarz <slusarz@horde.org>
 * @copyright  2012-2015 Horde LLC
 * @license    LGPL-2.1 (http://www.horde.org/licenses/lgpl21)
 */

var HordeImple = {

    actions: $H(),

    runImple: function(id, e)
    {
        var params = this.actions.get(id);

        if (Object.isString(params)) {
            eval(params);
        } else {
            if (e.type == 'submit' && e.element().match('FORM')) {
                params.imple_submit = Object.toJSON(e.element().serialize(true));
            }
            $(id).fire(params.imple + ':do', params);
            HordeCore.doAction('imple', params, {
                callback: this.impleCallback.bind(this, id)
            });
        }

        if (e) {
            e.stop();
        }
    },

    impleCallback: function(id, r)
    {
        $(id).fire(this.actions.get(id).imple + ':complete', r);
    },

    // args = id, observe, params
    add: function(args)
    {
        if (args) {
            this.actions.set(args.id, args.params);
            $(args.id).observe(args.observe, this.runImple.bind(this, args.id));
        }
    }

};