|
12 | 12 | var GenericAdmin = {
|
13 | 13 | url_array: null,
|
14 | 14 | fields: null,
|
15 |
| - obj_url: "../genericadmin-obj-data/", |
| 15 | + obj_url: "../obj-data/", |
16 | 16 | admin_media_url: window.__admin_media_prefix__,
|
17 | 17 | popup: '_popup',
|
18 |
| - |
| 18 | + |
19 | 19 | prepareSelect: function(select) {
|
20 | 20 | var that = this,
|
21 | 21 | opt_keys = [],
|
|
30 | 30 | if (this.value) {
|
31 | 31 | if (that.url_array[this.value]) {
|
32 | 32 | key = that.url_array[this.value][0].split('/')[0];
|
33 |
| - |
| 33 | + |
34 | 34 | opt = $(this).clone();
|
35 | 35 | opt.text(that.capFirst(opt.text()));
|
36 | 36 | if ($.inArray(key, opt_keys) < 0) {
|
|
47 | 47 | }
|
48 | 48 | });
|
49 | 49 | select.empty().append(no_value);
|
50 |
| - |
| 50 | + |
51 | 51 | opt_keys = opt_keys.sort();
|
52 | 52 |
|
53 | 53 | $.each(opt_keys, function(index, key) {
|
|
61 | 61 | return select;
|
62 | 62 | },
|
63 | 63 |
|
64 |
| - |
65 | 64 | getLookupUrlParams: function(cID) {
|
66 |
| - var q = this.url_array[cID][2] || {}, |
| 65 | + var q = this.url_array[cID][1] || {}, |
67 | 66 | str = [];
|
68 | 67 | for(var p in q) {
|
69 | 68 | str.push(encodeURIComponent(p) + "=" + encodeURIComponent(q[p]));
|
|
72 | 71 | url = x ? ("?" + x) : "";
|
73 | 72 | return url;
|
74 | 73 | },
|
75 |
| - |
76 |
| - getLookupUrl: function(cID, with_params) { |
77 |
| - var url = this.url_array[cID][1]; |
78 |
| - if(with_params){url = url + this.getLookupUrlParams(cID);} |
79 |
| - return url; |
| 74 | + |
| 75 | + getLookupUrl: function(cID) { |
| 76 | + return '../../../' + this.url_array[cID][0] + '/' + this.getLookupUrlParams(cID); |
80 | 77 | },
|
81 |
| - |
| 78 | + |
82 | 79 | getFkId: function() {
|
83 | 80 | if (this.fields.inline === false) {
|
84 | 81 | return 'id_' + this.fields.fk_field;
|
85 | 82 | } else {
|
86 | 83 | return ['id_', this.fields.prefix, '-', this.fields.number, '-', this.fields.fk_field].join('');
|
87 | 84 | }
|
88 | 85 | },
|
89 |
| - |
| 86 | + |
90 | 87 | getCtId: function() {
|
91 | 88 | if (this.fields.inline === false) {
|
92 | 89 | return 'id_' + this.fields.ct_field;
|
93 | 90 | } else {
|
94 | 91 | return ['id_', this.fields.prefix, '-', this.fields.number, '-', this.fields.ct_field].join('');
|
95 | 92 | }
|
96 | 93 | },
|
97 |
| - |
| 94 | + |
98 | 95 | capFirst: function(string) {
|
99 | 96 | return string.charAt(0).toUpperCase() + string.slice(1);
|
100 | 97 | },
|
101 |
| - |
| 98 | + |
102 | 99 | hideLookupLink: function() {
|
103 | 100 | var this_id = this.getFkId();
|
104 | 101 | $('#lookup_' + this_id).unbind().remove();
|
105 | 102 | $('#lookup_text_' + this_id + ' a').remove();
|
106 | 103 | $('#lookup_text_' + this_id + ' span').remove();
|
107 | 104 | },
|
108 |
| - |
| 105 | + |
109 | 106 | showLookupLink: function() {
|
110 | 107 | var that = this,
|
111 |
| - url = this.getLookupUrl(this.cID, true), |
| 108 | + url = this.getLookupUrl(this.cID), |
112 | 109 | id = 'lookup_' + this.getFkId(),
|
113 | 110 | link = '<a class="related-lookup" id="' + id + '" href="' + url + '"> </a>';
|
114 |
| - |
| 111 | + |
115 | 112 | link = link + '<strong id="lookup_text_'+ this.getFkId() +'" margin-left: 5px"><a target="_new" href="#"></a><span></span></strong>';
|
116 | 113 |
|
117 | 114 | // insert link html after input element
|
118 | 115 | this.object_input.after(link);
|
119 | 116 |
|
120 | 117 | return id;
|
121 | 118 | },
|
122 |
| - |
| 119 | + |
123 | 120 | pollInputChange: function(window) {
|
124 | 121 | var that = this,
|
125 | 122 | interval_id = setInterval(function() {
|
|
131 | 128 | },
|
132 | 129 | 150);
|
133 | 130 | },
|
134 |
| - |
| 131 | + |
135 | 132 | popRelatedObjectLookup: function(link) {
|
136 | 133 | var name = id_to_windowname(this.getFkId()),
|
137 | 134 | url_parts = [],
|
138 |
| - href, |
| 135 | + href, |
139 | 136 | win;
|
140 | 137 |
|
141 | 138 | if (link.href.search(/\?/) >= 0) {
|
|
159 | 156 | win.focus();
|
160 | 157 | return false;
|
161 | 158 | },
|
162 |
| - |
| 159 | + |
163 | 160 | updateObjectData: function() {
|
164 | 161 | var that = this;
|
165 | 162 | return function() {
|
166 | 163 | var value = that.object_input.val();
|
167 |
| - |
168 |
| - if (!value) { |
169 |
| - return |
| 164 | + |
| 165 | + if (!value) { |
| 166 | + return |
170 | 167 | }
|
171 | 168 | //var this_id = that.getFkId();
|
172 | 169 | $('#lookup_text_' + that.getFkId() + ' span').text('loading...');
|
|
179 | 176 | },
|
180 | 177 | success: function(item) {
|
181 | 178 | if (item && item.content_type_text && item.object_text) {
|
182 |
| - var url = that.getLookupUrl(that.cID, false); |
| 179 | + var url = that.getLookupUrl(that.cID); |
183 | 180 | $('#lookup_text_' + that.getFkId() + ' a')
|
184 | 181 | .text(item.content_type_text + ': ' + item.object_text)
|
185 | 182 | .attr('href', url + item.object_id);
|
|
211 | 208 | this.url_array = url_array;
|
212 | 209 | this.fields = fields;
|
213 | 210 | this.popup = popup_var || this.popup;
|
214 |
| - |
| 211 | + |
215 | 212 | // store the base element
|
216 | 213 | this.object_input = $("#" + this.getFkId());
|
217 |
| - |
| 214 | + |
218 | 215 | // find the select we need to change
|
219 | 216 | this.object_select = this.prepareSelect($("#" + this.getCtId()));
|
220 | 217 |
|
|
248 | 245 | this.updateObjectData()();
|
249 | 246 | }
|
250 | 247 | };
|
251 |
| - |
| 248 | + |
252 | 249 | var InlineAdmin = {
|
253 | 250 | sub_admins: null,
|
254 | 251 | url_array: null,
|
255 | 252 | fields: null,
|
256 | 253 | popup: '_popup',
|
257 |
| - |
| 254 | + |
258 | 255 | install: function(fields, url_array, popup_var) {
|
259 | 256 | var inline_count = $('#id_' + fields.prefix + '-TOTAL_FORMS').val(),
|
260 | 257 | admin;
|
261 |
| - |
| 258 | + |
262 | 259 | this.url_array = url_array;
|
263 | 260 | this.fields = fields;
|
264 | 261 | this.sub_admins = [];
|
265 | 262 | this.popup = popup_var || this.popup;
|
266 |
| - |
| 263 | + |
267 | 264 | for (var j = 0; j < inline_count; j++) {
|
268 | 265 | f = $.extend({}, this.fields);
|
269 | 266 | f.number = j;
|
|
282 | 279 | added_fields.number = ($('#id_' + that.fields.prefix + '-TOTAL_FORMS').val() - 1);
|
283 | 280 | admin.install(added_fields, that.url_array, that.popup);
|
284 | 281 | that.sub_admins.push(admin);
|
285 |
| - |
| 282 | + |
286 | 283 | $('#' + that.fields.prefix + '-' + added_fields.number + ' .inline-deletelink').click(
|
287 | 284 | that.removeHandler(that)
|
288 | 285 | );
|
|
293 | 290 | var parent_id,
|
294 | 291 | deleted_num,
|
295 | 292 | sub_admin;
|
296 |
| - |
| 293 | + |
297 | 294 | e.preventDefault();
|
298 | 295 | parent_id = $(e.currentTarget).parents('.dynamic-' + that.fields.prefix).first().attr('id');
|
299 | 296 | deleted_num = parseInt(parent_id.charAt(parent_id.length - 1), 10);
|
|
318 | 315 | ct_fields = data.fields,
|
319 | 316 | popup_var = data.popup_var,
|
320 | 317 | fields;
|
321 |
| - |
| 318 | + |
322 | 319 | for (var i = 0; i < ct_fields.length; i++) {
|
323 | 320 | fields = ct_fields[i];
|
324 | 321 | if (fields.inline === false) {
|
|
0 commit comments