+
+ // CRM-15759 - Workaround broken textarea handling in jeditable 1.7.1
+ $i.click(function() {
+ $('textarea', this).off()
+ // Fix cancel-on-blur
+ .on('blur', function(e) {
+ if (!e.relatedTarget || !$(e.relatedTarget).is('.crm-editable-form button')) {
+ $i.find('button[type=cancel]').click();
+ }
+ })
+ // Add support for ctrl-enter shortcut key
+ .on('keydown', function (e) {
+ if (e.ctrlKey && e.keyCode == 13) {
+ $i.find('button[type=submit]').click();
+ e.preventDefault();
+ }
+ });
+ });
+
+ function getData(value, settings) {
+ // Add css class to wrapper
+ // FIXME: This should be a response to an event instead of coupled with this function but jeditable 1.7.1 doesn't trigger any events :(
+ $i.addClass('crm-editable-editing');
+
+ originalValue = value;
+
+ if ($i.data('type') == 'select' || $i.data('type') == 'boolean') {
+ if ($i.data('options')) {
+ return formatOptions($i.data('options'));
+ }
+ var result,
+ info = $i.crmEditableEntity(),
+ hash = info.entity + '.' + info.field,
+ params = {
+ field: info.field,
+ context: 'create'
+ };
+ $i.data('optionsHashKey', hash);
+ if (!optionsCache[hash]) {
+ $.ajax({
+ url: CRM.url('civicrm/ajax/rest'),
+ data: {entity: info.entity, action: 'getoptions', json: JSON.stringify(params)},
+ async: false, // jeditable lacks support for async options lookup
+ success: function(data) {optionsCache[hash] = data.values;}
+ });
+ }
+ return formatOptions(optionsCache[hash]);
+ }
+ // Unwrap contents then replace html special characters with plain text
+ return _.unescape(value.replace(/<(?:.|\n)*?>/gm, ''));
+ }
+
+ function formatOptions(options) {
+ if (typeof $i.data('emptyOption') === 'string') {
+ // Using 'null' because '' is broken in jeditable 1.7.1
+ return $.extend({'null': $i.data('emptyOption')}, options);
+ }
+ return options;
+ }
+
+ function restoreContainer() {
+ if (errorMsg && errorMsg.close) errorMsg.close();
+ $i.removeClass('crm-editable-saving crm-editable-editing');
+ }
+