Add notification for editing search / replace

This commit is contained in:
Romain Neutron
2012-02-16 18:59:08 +01:00
parent 65e98b0478
commit 400db81f28
3 changed files with 90 additions and 85 deletions

View File

@@ -95,6 +95,7 @@ class Language implements ControllerProviderInterface
$out['FeedBackDuration'] = _('Time for feedback (days)'); $out['FeedBackDuration'] = _('Time for feedback (days)');
$out['send'] = _('Send'); $out['send'] = _('Send');
$out['Recept'] = _('Accuse de reception'); $out['Recept'] = _('Accuse de reception');
$out['nFieldsChanged'] = _('%d fields have been updated');
$out['FeedBackNoUsersSelected'] = _('No users selected'); $out['FeedBackNoUsersSelected'] = _('No users selected');
$Serializer = $app['Core']['Serializer']; $Serializer = $app['Core']['Serializer'];

View File

@@ -1,6 +1,6 @@
(function( window ) { (function( window ) {
function checkVocabId(VocabularyId) function checkVocabId(VocabularyId)
{ {
if(typeof VocabularyId === 'undefined') if(typeof VocabularyId === 'undefined')
@@ -8,23 +8,23 @@
if(VocabularyId === '') if(VocabularyId === '')
VocabularyId = null; VocabularyId = null;
return VocabularyId; return VocabularyId;
} }
var recordFieldValue = function(meta_id, value, VocabularyId) { var recordFieldValue = function(meta_id, value, VocabularyId) {
VocabularyId = checkVocabId(VocabularyId); VocabularyId = checkVocabId(VocabularyId);
this.datas = { this.datas = {
meta_id:meta_id, meta_id:meta_id,
value:value, value:value,
VocabularyId:VocabularyId VocabularyId:VocabularyId
}; };
var $this = this; var $this = this;
}; };
recordFieldValue.prototype = { recordFieldValue.prototype = {
getValue : function() { getValue : function() {
return this.datas.value; return this.datas.value;
@@ -36,7 +36,7 @@
return this.datas.VocabularyId; return this.datas.VocabularyId;
}, },
setValue : function(value, VocabularyId) { setValue : function(value, VocabularyId) {
this.datas.value = value; this.datas.value = value;
this.datas.VocabularyId = checkVocabId(VocabularyId); this.datas.VocabularyId = checkVocabId(VocabularyId);
return this; return this;
@@ -44,13 +44,13 @@
remove : function() { remove : function() {
this.datas.value = ''; this.datas.value = '';
this.datas.VocabularyId = null; this.datas.VocabularyId = null;
return this; return this;
} }
}; };
var databoxField = function(name, meta_struct_id, options) { var databoxField = function(name, meta_struct_id, options) {
var defaults = { var defaults = {
multi : false, multi : false,
required : false, required : false,
@@ -63,23 +63,23 @@
vocabularyRestricted : false vocabularyRestricted : false
}, },
options = (typeof options == 'object') ? options : {}; options = (typeof options == 'object') ? options : {};
if(isNaN(meta_struct_id)) if(isNaN(meta_struct_id))
{ {
throw 'meta_struct_id should be a number'; throw 'meta_struct_id should be a number';
} }
this.name = name; this.name = name;
this.meta_struct_id = meta_struct_id; this.meta_struct_id = meta_struct_id;
this.options = jQuery.extend(defaults, options); this.options = jQuery.extend(defaults, options);
if(this.options.multi === true && this.options.separator === null) if(this.options.multi === true && this.options.separator === null)
{ {
this.options.separator = ';'; this.options.separator = ';';
} }
}; };
databoxField.prototype = { databoxField.prototype = {
getMetaStructId : function() { getMetaStructId : function() {
return this.meta_struct_id; return this.meta_struct_id;
@@ -109,9 +109,9 @@
return this.options.separator; return this.options.separator;
} }
}; };
var recordField = function(databoxField, arrayValues) { var recordField = function(databoxField, arrayValues) {
this.databoxField = databoxField; this.databoxField = databoxField;
this.options = { this.options = {
dirty : false dirty : false
@@ -122,9 +122,9 @@
{ {
if(arrayValues.length > 1 && !databoxField.isMulti()) if(arrayValues.length > 1 && !databoxField.isMulti())
throw 'You can not add multiple values to a non multi field'; throw 'You can not add multiple values to a non multi field';
var first = true; var first = true;
for(v in arrayValues) for(v in arrayValues)
{ {
if(typeof arrayValues[v] !== 'object') if(typeof arrayValues[v] !== 'object')
@@ -133,20 +133,20 @@
{ {
console.error('Trying to add a non-recordFieldValue to the field...'); console.error('Trying to add a non-recordFieldValue to the field...');
} }
continue; continue;
} }
if(isNaN(arrayValues[v].getMetaId())) if(isNaN(arrayValues[v].getMetaId()))
{ {
if(window.console) if(window.console)
{ {
console.error('Trying to add a recordFieldValue without metaId...'); console.error('Trying to add a recordFieldValue without metaId...');
} }
continue; continue;
} }
if(!first && this.options.multi === false) if(!first && this.options.multi === false)
{ {
if(window.console) if(window.console)
@@ -154,17 +154,17 @@
console.error('Trying to add multi values in a non-multi field'); console.error('Trying to add multi values in a non-multi field');
} }
} }
if(window.console) if(window.console)
{ {
console.log('adding a value : ', arrayValues[v]); console.log('adding a value : ', arrayValues[v]);
} }
this.datas.push(arrayValues[v]); this.datas.push(arrayValues[v]);
first = false; first = false;
} }
} }
var $this = this; var $this = this;
} }
recordField.prototype = { recordField.prototype = {
@@ -184,26 +184,26 @@
return this.options.dirty; return this.options.dirty;
}, },
addValue : function(value, merge, VocabularyId) { addValue : function(value, merge, VocabularyId) {
VocabularyId = checkVocabId(VocabularyId); VocabularyId = checkVocabId(VocabularyId);
merge = !!merge; merge = !!merge;
if(this.databoxField.isReadonly()) if(this.databoxField.isReadonly())
{ {
if(window.console) if(window.console)
{ {
console.error('Unable to set a value to a readonly field'); console.error('Unable to set a value to a readonly field');
} }
return; return;
} }
if(window.console) if(window.console)
{ {
console.log('adding value ',value,' vocId : ', VocabularyId , ' ; merge is ',merge); console.log('adding value ',value,' vocId : ', VocabularyId , ' ; merge is ',merge);
} }
if(this.isMulti()) if(this.isMulti())
{ {
if(!this.hasValue(value, VocabularyId)) if(!this.hasValue(value, VocabularyId))
@@ -232,10 +232,10 @@
console.log('Merging value ',value); console.log('Merging value ',value);
} }
this.datas[0].setValue(this.datas[0].getValue() + ' ' + value, VocabularyId); this.datas[0].setValue(this.datas[0].getValue() + ' ' + value, VocabularyId);
this.options.dirty = true; this.options.dirty = true;
} }
else else
{ {
if(merge === true && this.isEmpty() === false && VocabularyId !== null) if(merge === true && this.isEmpty() === false && VocabularyId !== null)
{ {
@@ -247,7 +247,7 @@
} }
else else
{ {
if(!this.hasValue(value, VocabularyId)) if(!this.hasValue(value, VocabularyId))
{ {
if(this.datas.length === 0) if(this.datas.length === 0)
@@ -271,11 +271,11 @@
} }
} }
} }
return this; return this;
}, },
hasValue : function(value, VocabularyId) { hasValue : function(value, VocabularyId) {
if(typeof value === 'undefined') if(typeof value === 'undefined')
{ {
if(window.console) if(window.console)
@@ -283,9 +283,9 @@
console.error('Trying to check the presence of an undefined value'); console.error('Trying to check the presence of an undefined value');
} }
} }
VocabularyId = checkVocabId(VocabularyId); VocabularyId = checkVocabId(VocabularyId);
for(d in this.datas) for(d in this.datas)
{ {
if(VocabularyId !== null) if(VocabularyId !== null)
@@ -311,24 +311,24 @@
return false; return false;
}, },
removeValue : function(value, vocabularyId) { removeValue : function(value, vocabularyId) {
if(this.databoxField.isReadonly()) if(this.databoxField.isReadonly())
{ {
if(window.console) if(window.console)
{ {
console.error('Unable to set a value to a readonly field'); console.error('Unable to set a value to a readonly field');
} }
return; return;
} }
vocabularyId = checkVocabId(vocabularyId); vocabularyId = checkVocabId(vocabularyId);
if(window.console) if(window.console)
{ {
console.log('Try to remove value ', value, vocabularyId, this.datas); console.log('Try to remove value ', value, vocabularyId, this.datas);
} }
for(d in this.datas) for(d in this.datas)
{ {
if(window.console) if(window.console)
@@ -361,7 +361,7 @@
}, },
isEmpty : function() { isEmpty : function() {
var empty = true; var empty = true;
for(d in this.datas) for(d in this.datas)
{ {
if(this.datas[d].getValue() !== '') if(this.datas[d].getValue() !== '')
@@ -370,17 +370,17 @@
return empty; return empty;
}, },
empty : function() { empty : function() {
if(this.databoxField.isReadonly()) if(this.databoxField.isReadonly())
{ {
if(window.console) if(window.console)
{ {
console.error('Unable to set a value to a readonly field'); console.error('Unable to set a value to a readonly field');
} }
return; return;
} }
for(d in this.datas) for(d in this.datas)
{ {
this.datas[d].remove(); this.datas[d].remove();
@@ -389,100 +389,101 @@
return this; return this;
}, },
getValue : function() { getValue : function() {
if(this.isMulti()) if(this.isMulti())
throw 'This field is multi, I can not give you a single value'; throw 'This field is multi, I can not give you a single value';
if(this.isEmpty()) if(this.isEmpty())
return null; return null;
return this.datas[0]; return this.datas[0];
}, },
getValues : function() { getValues : function() {
if(!this.isMulti()) if(!this.isMulti())
{ {
throw 'This field is not multi, I can not give you multiple values'; throw 'This field is not multi, I can not give you multiple values';
} }
if(this.isEmpty()) if(this.isEmpty())
return new Array(); return new Array();
var arrayValues = []; var arrayValues = [];
for(d in this.datas) for(d in this.datas)
{ {
if(this.datas[d].getValue() === '') if(this.datas[d].getValue() === '')
continue; continue;
arrayValues.push(this.datas[d]); arrayValues.push(this.datas[d]);
} }
return arrayValues; return arrayValues;
}, },
sort : function(algo) { sort : function(algo) {
this.datas.sort(algo); this.datas.sort(algo);
return this; return this;
}, },
getSerializedValues : function() { getSerializedValues : function() {
var arrayValues = []; var arrayValues = [];
var values = this.getValues(); var values = this.getValues();
for(v in values) for(v in values)
{ {
arrayValues.push(values[v].getValue()); arrayValues.push(values[v].getValue());
} }
return arrayValues.join(' ' + this.databoxField.getSeparator() + ' '); return arrayValues.join(' ' + this.databoxField.getSeparator() + ' ');
}, },
replaceValue : function(search, replace) { replaceValue : function(search, replace) {
if(this.databoxField.isReadonly()) if(this.databoxField.isReadonly())
{ {
if(window.console) if(window.console)
{ {
console.error('Unable to set a value to a readonly field'); console.error('Unable to set a value to a readonly field');
} }
return; return 0;
} }
var n = 0;
for(d in this.datas) for(d in this.datas)
{ {
if(this.datas[d].getVocabularyId() !== null) if(this.datas[d].getVocabularyId() !== null)
{ {
continue; continue;
} }
var value = this.datas[d].getValue(); var value = this.datas[d].getValue();
var replacedValue = value.replace(search, replace); var replacedValue = value.replace(search, replace);
if(value === replacedValue) if(value === replacedValue)
{ {
continue; continue;
} }
n++;
this.removeValue(value); this.removeValue(value);
if(!this.hasValue(replacedValue)) if(!this.hasValue(replacedValue))
{ {
this.addValue(replacedValue); this.addValue(replacedValue);
} }
this.options.dirty = true; this.options.dirty = true;
} }
/** return n;
* cleanup and remove duplicates
*/
return this;
}, },
exportDatas : function() { exportDatas : function() {
var returnValue = new Array(); var returnValue = new Array();
for(d in this.datas) for(d in this.datas)
{ {
var temp = { var temp = {
@@ -490,22 +491,22 @@
meta_struct_id : this.getMetaStructId(), meta_struct_id : this.getMetaStructId(),
value : this.datas[d].getValue() value : this.datas[d].getValue()
}; };
if(this.datas[d].getVocabularyId()) if(this.datas[d].getVocabularyId())
{ {
temp.vocabularyId = this.datas[d].getVocabularyId(); temp.vocabularyId = this.datas[d].getVocabularyId();
} }
returnValue.push(temp); returnValue.push(temp);
} }
return returnValue; return returnValue;
} }
}; };
window.p4 = window.p4 || {}; window.p4 = window.p4 || {};
window.p4.databoxField = databoxField; window.p4.databoxField = databoxField;
window.p4.recordFieldValue = recordFieldValue; window.p4.recordFieldValue = recordFieldValue;
window.p4.recordField = recordField; window.p4.recordField = recordField;
})(window); })(window);

View File

@@ -1454,7 +1454,7 @@ function replace()
search = new RegExp(r_search, commut); search = new RegExp(r_search, commut);
var r, f; var r, f, n = 0;
for(r in p4.edit.T_records) for(r in p4.edit.T_records)
{ {
if(!p4.edit.T_records[r]._selected) if(!p4.edit.T_records[r]._selected)
@@ -1463,10 +1463,13 @@ function replace()
{ {
if(field == '' || field==f) if(field == '' || field==f)
{ {
p4.edit.T_records[r].fields[f].replaceValue(search, replace); n += p4.edit.T_records[r].fields[f].replaceValue(search, replace);
} }
} }
} }
humane.info($.sprintf(language.nFieldsChanged, n));
updateEditSelectedRecords(null); updateEditSelectedRecords(null);
} }