mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-02-07 01:54:16 +01:00
Contacts: Prevent adding new group while editing one.
This commit is contained in:
parent
ba83e30ce5
commit
fa452fd0ea
22
js/app.js
22
js/app.js
@ -460,6 +460,10 @@ GroupList.prototype.deleteGroup = function(groupid, cb) {
|
|||||||
|
|
||||||
GroupList.prototype.editGroup = function(id) {
|
GroupList.prototype.editGroup = function(id) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
if(this.$editelem) {
|
||||||
|
console.log('Already editing, returning');
|
||||||
|
return;
|
||||||
|
}
|
||||||
// NOTE: Currently this only works for adding, not renaming
|
// NOTE: Currently this only works for adding, not renaming
|
||||||
var saveChanges = function($elem, $input) {
|
var saveChanges = function($elem, $input) {
|
||||||
console.log('saveChanges', $input.val());
|
console.log('saveChanges', $input.val());
|
||||||
@ -474,6 +478,7 @@ GroupList.prototype.editGroup = function(id) {
|
|||||||
$elem.prepend(name).removeClass('editing').attr('data-id', response.id);
|
$elem.prepend(name).removeClass('editing').attr('data-id', response.id);
|
||||||
$input.next('.checked').remove()
|
$input.next('.checked').remove()
|
||||||
$input.remove()
|
$input.remove()
|
||||||
|
self.$editelem = null;
|
||||||
} else {
|
} else {
|
||||||
$input.prop('disabled', false);
|
$input.prop('disabled', false);
|
||||||
OC.notify({message:response.message});
|
OC.notify({message:response.message});
|
||||||
@ -484,17 +489,17 @@ GroupList.prototype.editGroup = function(id) {
|
|||||||
if(typeof id === 'undefined') {
|
if(typeof id === 'undefined') {
|
||||||
// Add new group
|
// Add new group
|
||||||
var tmpl = this.$groupListItemTemplate;
|
var tmpl = this.$groupListItemTemplate;
|
||||||
var $elem = (tmpl).octemplate({
|
self.$editelem = (tmpl).octemplate({
|
||||||
id: 'new',
|
id: 'new',
|
||||||
type: 'category',
|
type: 'category',
|
||||||
num: 0,
|
num: 0,
|
||||||
name: '',
|
name: '',
|
||||||
});
|
});
|
||||||
var $input = $('<input type="text" class="active" /><a class="action checked disabled" />');
|
var $input = $('<input type="text" class="active" /><a class="action checked disabled" />');
|
||||||
$elem.prepend($input).addClass('editing');
|
self.$editelem.prepend($input).addClass('editing');
|
||||||
$elem.data('contacts', []);
|
self.$editelem.data('contacts', []);
|
||||||
this.$groupList.find('h3.group[data-type="category"]').first().before($elem);
|
this.$groupList.find('h3.group[data-type="category"]').first().before(self.$editelem);
|
||||||
this.selectGroup({element:$elem});
|
this.selectGroup({element:self.$editelem});
|
||||||
$input.on('input', function(event) {
|
$input.on('input', function(event) {
|
||||||
if($(this).val().length > 0) {
|
if($(this).val().length > 0) {
|
||||||
$(this).next('.checked').removeClass('disabled');
|
$(this).next('.checked').removeClass('disabled');
|
||||||
@ -505,9 +510,10 @@ GroupList.prototype.editGroup = function(id) {
|
|||||||
$input.on('keyup', function(event) {
|
$input.on('keyup', function(event) {
|
||||||
var keyCode = Math.max(event.keyCode, event.which);
|
var keyCode = Math.max(event.keyCode, event.which);
|
||||||
if(keyCode === 13) {
|
if(keyCode === 13) {
|
||||||
saveChanges($elem, $(this));
|
saveChanges(self.$editelem, $(this));
|
||||||
} else if(keyCode === 27) {
|
} else if(keyCode === 27) {
|
||||||
$elem.remove();
|
self.$editelem.remove();
|
||||||
|
self.$editelem = null;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$input.next('.checked').on('click keydown', function(event) {
|
$input.next('.checked').on('click keydown', function(event) {
|
||||||
@ -515,7 +521,7 @@ GroupList.prototype.editGroup = function(id) {
|
|||||||
if(wrongKey(event)) {
|
if(wrongKey(event)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
saveChanges($elem, $input);
|
saveChanges(self.$editelem, $input);
|
||||||
});
|
});
|
||||||
$input.focus();
|
$input.focus();
|
||||||
} else if(utils.isUInt(id)) {
|
} else if(utils.isUInt(id)) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user