Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 30 additions & 22 deletions editable.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mEditable = {
var t = this._types.findOne({_id: type });
if (!t)
throw new Meteor.Error(500, 'Editable type ' + type + ' is not defined.');
return Template[t.template];
return Template[t.template] || null;
},
getVal: function (type) {
return this._types.findOne({_id: type }).getVal;
Expand All @@ -27,7 +27,13 @@ mEditable = {
})
});
// store only the template name
type.template = type.template.kind.replace(/^Template_/, '');
if (type.template.viewName) {
type.template = type.template.viewName.replace(/Template\./, '');
} else if (!type.template.kind) {
type.template = type.template.__templateName;
} else {
type.template = type.template.kind.replace(/^Template_/, '');
}
return this._types.insert(type);
}
};
Expand All @@ -43,11 +49,11 @@ m_editable.helpers({
return Template.m_editable_handle_atag;
},
'displayVal': function () {
var v = valueToText(this.value, this.source) || this.emptyText;
if (typeof this.display === 'function') {
return this.display(v, this.value) || this.emptyText;
}
return v || this.emptyText;
value = Session.get('displayValue');
if (!value) {
Session.set('displayValue', true);
}
return valueToDisplay(this);
},
'value': function () { return valueToText(this.value, this.source) || this.emptyText; },
'editableEmpty': function () {
Expand All @@ -71,21 +77,21 @@ m_editable.events({
'submit': function (e, tmpl) {
var self = this;

var val = mEditable.getVal(this.type)(tmpl.$('.editable-input'));
var val = mEditable.getVal(self.type)(tmpl.$('.editable-input'));

if (typeof self.onsubmit === 'function') {
if (typeof self.onsubmit === 'function') {
if (self.async) {
tmpl.Session.set('loading', true);
this.onsubmit.call(this, val, function () {
self.onsubmit.call(self, val, function () {
tmpl.$('.m_editable-popup').trigger('hide');
doSavedTransition(tmpl);
});
return;
}
this.onsubmit.call(this, val);
} else {
tmpl.$('.editable-click').text(val);
}
self.onsubmit.call(self, val);
}
self.value = val;
Session.set('displayValue', true);
tmpl.$('.m_editable-popup').trigger('hide');
doSavedTransition(tmpl);
},
Expand Down Expand Up @@ -210,6 +216,14 @@ function valueToText(val, source) {
return val[0];
}

function valueToDisplay(tmpl) {
var v = valueToText(tmpl.value, tmpl.source) || tmpl.emptyText;
if (typeof tmpl.display === 'function') {
return tmpl.display(v, tmpl.value) || tmpl.emptyText;
}
return v || tmpl.emptyText;
}

function generateSettings (settings) {
if (POSSIBLE_POSITIONS.indexOf(settings.position) == -1)
delete settings.position;
Expand All @@ -221,6 +235,7 @@ function generateSettings (settings) {
async: false,
showbuttons: true,
onsubmit: null,
display:null,
value: null,
position: 'left',
title: null,
Expand All @@ -229,15 +244,8 @@ function generateSettings (settings) {
}

function doSavedTransition (tmpl) {
var $e = tmpl.$('.editable-click'),
bgColor = $e.css('background-color');

$e.css('background-color', '#FFFF80');
var $e = tmpl.$('.editable-click');
setTimeout(function(){
if(bgColor === 'transparent') {
bgColor = '';
}
$e.css('background-color', bgColor);
$e.addClass('editable-bg-transition');
setTimeout(function(){
$e.removeClass('editable-bg-transition');
Expand Down
9 changes: 3 additions & 6 deletions inputs/date/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Template.m_editable_form_date.events({
e.stopImmediatePropagation();
},
'changeDate': function (e) {
if (e.date && !this.showbuttons && e.date.getTime() !== getCurrentValsTime(this.value)) {
if (e.date && !this.showbuttons) {
$(e.target).closest('form').submit();
}

Expand All @@ -51,11 +51,8 @@ Template.m_editable_form_date.rendered = function () {

function initializeDatepicker(div) {
return div.datepicker({
weekStart: 0,
startView: 0,
minViewMode: 0,
autoclose: false
});
todayBtn: "linked",
todayHighlight: true});
}

function stripTimeFromDate(date) {
Expand Down
Loading