+ // Compute a digest over the list of files. The signature should change if the attachment list has changed
+ // (become dirty).
+ getAutosaveSignature: function getAutosaveSignature() {
+ var sig = [];
+ // Attachments have a special lifecycle, and attachments.queue is not properly serializable, so
+ // it takes some special effort to figure out a suitable signature. Issues which can cause gratuitous saving:
+ // - Files move from this.uploader.queue to this.files after upload.
+ // - File names are munged after upload.
+ // - Deletes are performed immediately (outside the save process).
+ angular.forEach(this.files, function(item) {
+ sig.push({f: item.name.replace(/[^a-zA0-Z0-9\.]/, '_'), d: item.description});
+ });
+ angular.forEach(this.uploader.queue, function(item) {
+ sig.push({f: item.file.name.replace(/[^a-zA0-Z0-9\.]/, '_'), d: item.crmData.description});
+ });
+ angular.forEach(this.trash, function(item) {
+ sig.push({f: item.name.replace(/[^a-zA0-Z0-9\.]/, '_'), d: item.description});
+ });
+ return _.sortBy(sig, 'name');
+ },