1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 $.fn.editable.defaults.ajaxOptions = {type: 'post', dataType: 'json'};
6 $.fn.editable.defaults.send = 'always';
8 // Default for editing is popup. I experimented with inline which is a little
9 // nicer in that it shows up right under the mouse instead of nearby. However,
10 // the inline box is taller than the regular content, which causes the page
11 // layout to shift unless we make the table rows tall, which leaves a lot of
12 // wasted space when not editing. Also inline can get cut off if the page is
13 // too narrow, when the popup box will just move to do the right thing.
14 //$.fn.editable.defaults.mode = 'inline';
16 $.fn.editable.defaults.success = function (response, newValue) {
17 $(document).trigger('editable:success', [this, response, newValue]);
20 $.fn.editable.defaults.params = function (params) {
22 var key = params.pk.key;
23 a.id = $(this).attr('data-object-uuid') || params.pk.id;
24 a[key] = params.pk.defaults || {};
25 // Remove null values. Otherwise they get transmitted as empty
26 // strings in request params.
28 if (a[key][i] == null)
31 a[key][params.name] = params.value;
33 a['_method'] = 'post';
40 $.fn.editable.defaults.validate = function (value) {
41 if (value == "***invalid***") {
42 return "Invalid selection";
47 on('ready ajax:complete', function() {
49 not('.editable-done-setup').
50 addClass('editable-done-setup').
52 success: function(response, newValue) {
53 // If we just created a new object, stash its UUID
54 // so we edit it next time instead of creating
55 // another new object.
56 if (!$(this).attr('data-object-uuid') && response.uuid) {
57 $(this).attr('data-object-uuid', response.uuid);
60 $(this).editable('option', 'url', response.href);
62 if ($(this).attr('data-name')) {
63 var textileAttr = $(this).attr('data-name') + 'Textile';
64 if (response[textileAttr]) {
65 $(this).attr('data-textile', response[textileAttr]);
70 error: function(response, newValue) {
71 var errlist = response.responseJSON.errors;
73 if (Array.isArray(errlist)) {
74 errmsg = errlist.join();
76 errmsg = ("The server returned an error when making " +
77 "this update (status " + response.status +
78 ": " + errlist + ").");
83 on('hidden', function(e, reason) {
84 // After saving a new attribute, update the same
85 // information if it appears elsewhere on the page.
86 if (reason != 'save') return;
87 var html = $(this).html();
88 if( $(this).attr('data-textile') ) {
89 html = $(this).attr('data-textile');
92 var uuid = $(this).attr('data-object-uuid');
93 var attr = $(this).attr('data-name');
96 $("[data-object-uuid='" + uuid + "']" +
97 "[data-name='" + attr + "']").each(function() {
104 on('ready ajax:complete', function() {
105 $("[data-toggle~='x-editable']").
106 not('.editable-done-setup').
107 addClass('editable-done-setup').
110 $($(this).attr('data-toggle-selector')).editable('toggle');
114 $.fn.editabletypes.text.defaults.tpl = '<input type="text" name="editable-text">'
116 $.fn.editableform.buttons = '\
117 <button type="submit" class="btn btn-primary btn-sm editable-submit" \
118 id="editable-submit"><i class="glyphicon glyphicon-ok"></i></button>\
119 <button type="button" class="btn btn-default btn-sm editable-cancel" \
120 id="editable-cancel"><i class="glyphicon glyphicon-remove"></i></button>\