Skip to content

Commit 5bde046

Browse files
author
Friedrich W. H. Kossebau
committed
Merge methods only used by ops.ODtDocument.executeOperation
Also merge creator metadata update signal into any existing metadata update signal
1 parent 5da7c3c commit 5bde046

File tree

1 file changed

+33
-34
lines changed

1 file changed

+33
-34
lines changed

webodf/lib/ops/OdtDocument.js

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -437,31 +437,27 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
437437
return {textNode: lastTextNode, offset: nodeOffset };
438438
}
439439

440-
/**
441-
* @param {!ops.Operation} op
442-
* @return {undefined}
443-
*/
444-
function prepareOperationExecution(op) {
445-
eventNotifier.emit(ops.OdtDocument.signalOperationStart, op);
446-
}
447-
448440
/**
449441
* Called after an operation is executed, this
450442
* function will check if the operation is an
451443
* 'edit', and in that case will update the
452444
* document's metadata, such as dc:creator,
453445
* meta:editing-cycles, and dc:creator.
454446
* @param {!ops.Operation} op
447+
* @param {!Array.<!ops.Operation.Event>} events
455448
* @return {undefined}
456449
*/
457-
function finishOperationExecution(op) {
450+
function finishOperationExecution(op, events) {
458451
var opspec = op.spec(),
459452
memberId = opspec.memberid,
460453
date = new Date(opspec.timestamp).toISOString(),
461454
odfContainer = odfCanvas.odfContainer(),
462-
/**@type{!{setProperties: !Object, removedProperties: ?Array.<!string>}}*/
455+
/**@type{!ops.Operation.Event}*/
456+
changedMetadataEvent,
457+
/**@type{!{setProperties: !Object, removedProperties: !Array.<!string>}}*/
463458
changedMetadata,
464-
fullName;
459+
fullName,
460+
i;
465461

466462
// If the operation is an edit (that changes the
467463
// ODF that will be saved), then update metadata.
@@ -472,13 +468,25 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
472468
"dc:date": date
473469
}, null);
474470

475-
changedMetadata = {
476-
setProperties: {
477-
"dc:creator": fullName,
478-
"dc:date": date
479-
},
480-
removedProperties: []
481-
};
471+
// find any existing metadataupdated event or create one
472+
for (i = 0; i < events.length; i += 1) {
473+
if (events[i].eventid === ops.OdtDocument.signalMetadataUpdated) {
474+
changedMetadataEvent = events[i];
475+
changedMetadata = /**@type{!{setProperties: !Object, removedProperties: !Array.<!string>}}*/(changedMetadataEvent.args);
476+
break;
477+
}
478+
}
479+
if (!changedMetadataEvent) {
480+
changedMetadata = { setProperties: {}, removedProperties: [] };
481+
changedMetadataEvent = {
482+
eventid: ops.OdtDocument.signalMetadataUpdated,
483+
args: changedMetadata
484+
};
485+
events.push(changedMetadataEvent);
486+
}
487+
488+
changedMetadata.setProperties["dc:creator"] = fullName;
489+
changedMetadata.setProperties["dc:date"] = date;
482490

483491
// If no previous op was found in this session,
484492
// then increment meta:editing-cycles by 1.
@@ -500,16 +508,6 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
500508

501509
eventNotifier.emit(ops.OdtDocument.signalOperationEnd, op);
502510

503-
if (op.isEdit) {
504-
eventNotifier.emit(ops.OdtDocument.signalMetadataUpdated, changedMetadata);
505-
}
506-
}
507-
508-
/**
509-
* @param {!Array.<!ops.Operation.Event>} events
510-
* @return {undefined}
511-
*/
512-
function emitEvents(events) {
513511
events.forEach(function(event) {
514512
eventNotifier.emit(event.eventid, event.args);
515513
});
@@ -522,14 +520,15 @@ ops.OdtDocument = function OdtDocument(odfCanvas) {
522520
this.executeOperation = function(op) {
523521
var events;
524522

525-
prepareOperationExecution(op);
523+
eventNotifier.emit(ops.OdtDocument.signalOperationStart, op);
524+
526525
events = op.execute(self);
527-
if (events !== null) {
528-
finishOperationExecution(op);
529-
emitEvents(events);
530-
return true;
526+
if (events === null) {
527+
return false;
531528
}
532-
return false;
529+
530+
finishOperationExecution(op, events);
531+
return true;
533532
};
534533

535534
/**

0 commit comments

Comments
 (0)