1 | (function() {
|
2 | var Action, Ajax, AjaxUtils, Collection, Extend, Include, Singleton, View, ajax_request, _3Model,
|
3 | __slice = [].slice;
|
4 |
|
5 | _3Model = require('3vot-model');
|
6 |
|
7 | AjaxUtils = require("./ajax_utils");
|
8 |
|
9 | Collection = require("./ajax_collection");
|
10 |
|
11 | Singleton = require("./ajax_singleton");
|
12 |
|
13 | Action = require("./ajax_action");
|
14 |
|
15 | View = require("./ajax_view");
|
16 |
|
17 | ajax_request = require("./ajax_request");
|
18 |
|
19 | Include = {
|
20 | ajax: function() {
|
21 | return new Singleton(this);
|
22 | },
|
23 | url: function() {
|
24 | var args;
|
25 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
26 | args.unshift(encodeURIComponent(this.id));
|
27 | return AjaxUtils.generateURL.apply(AjaxUtils, [this].concat(__slice.call(args)));
|
28 | }
|
29 | };
|
30 |
|
31 | Extend = {
|
32 | ajax: function() {
|
33 | return new Collection(this);
|
34 | },
|
35 | view: function() {
|
36 | return new View(this);
|
37 | },
|
38 | action: function() {
|
39 | return new Action(this);
|
40 | },
|
41 | url: function() {
|
42 | var args;
|
43 | args = 1 <= arguments.length ? __slice.call(arguments, 0) : [];
|
44 | return AjaxUtils.generateURL.apply(AjaxUtils, [this].concat(__slice.call(args)));
|
45 | }
|
46 | };
|
47 |
|
48 | Ajax = {
|
49 | extended: function() {
|
50 | this.fetch(this.ajaxFetch);
|
51 | this.extend(Extend);
|
52 | return this.include(Include);
|
53 | },
|
54 | ajaxFetch: function() {
|
55 | var _ref;
|
56 | return (_ref = this.ajax()).fetch.apply(_ref, arguments);
|
57 | },
|
58 | callAction: function() {
|
59 | var _ref;
|
60 | return (_ref = this.action()).call.apply(_ref, arguments);
|
61 | },
|
62 | callView: function() {
|
63 | var _ref;
|
64 | return (_ref = this.view()).call.apply(_ref, arguments);
|
65 | },
|
66 | destroy: function() {
|
67 | var _ref;
|
68 | return (_ref = this.action()).destroy.apply(_ref, arguments);
|
69 | }
|
70 | };
|
71 |
|
72 | Ajax.Auto = {
|
73 | extended: function() {
|
74 | return this.change(this.ajaxChange);
|
75 | },
|
76 | ajaxChange: function(record, type, options) {
|
77 | if (options == null) {
|
78 | options = {};
|
79 | }
|
80 | if (options.ajax === false) {
|
81 | return;
|
82 | }
|
83 | return record.ajax()[type](options.ajax || {}, options);
|
84 | }
|
85 | };
|
86 |
|
87 | if (!_3Model.Model.host) {
|
88 | _3Model.Model.host = "";
|
89 | }
|
90 |
|
91 | if (!_3Model.Model.headers) {
|
92 | _3Model.Model.headers = [];
|
93 | }
|
94 |
|
95 | Ajax.request = ajax_request;
|
96 |
|
97 | module.exports = Ajax;
|
98 |
|
99 | }).call(this);
|