2013-09-09 00:08:55 +00:00
|
|
|
define([
|
|
|
|
"underscore",
|
|
|
|
"utils",
|
|
|
|
"ace/range"
|
|
|
|
], function(_, utils, range) {
|
|
|
|
var Range = range.Range;
|
2013-06-16 10:47:45 +00:00
|
|
|
|
|
|
|
function FileDescriptor(fileIndex, title, syncLocations, publishLocations) {
|
|
|
|
this.fileIndex = fileIndex;
|
2013-06-19 20:33:46 +00:00
|
|
|
this._title = title || localStorage[fileIndex + ".title"];
|
2013-06-16 10:47:45 +00:00
|
|
|
this._editorScrollTop = parseInt(localStorage[fileIndex + ".editorScrollTop"]) || 0;
|
2013-09-09 00:08:55 +00:00
|
|
|
this._editorSelectRange = (function() {
|
|
|
|
try {
|
|
|
|
var rangeComponents = localStorage[fileIndex + ".editorSelectRange"].split(';');
|
|
|
|
rangeComponents = _.map(rangeComponents, function(component) {
|
|
|
|
return parseInt(component);
|
|
|
|
});
|
|
|
|
return new Range(rangeComponents[0], rangeComponents[1], rangeComponents[2], rangeComponents[3]);
|
|
|
|
}
|
|
|
|
catch(e) {
|
2013-09-09 23:32:24 +00:00
|
|
|
return new Range(0, 0, 0, 0);
|
2013-09-09 00:08:55 +00:00
|
|
|
}
|
|
|
|
})();
|
2013-06-16 10:47:45 +00:00
|
|
|
this._editorEnd = parseInt(localStorage[fileIndex + ".editorEnd"]) || 0;
|
|
|
|
this._previewScrollTop = parseInt(localStorage[fileIndex + ".previewScrollTop"]) || 0;
|
|
|
|
this._selectTime = parseInt(localStorage[fileIndex + ".selectTime"]) || 0;
|
|
|
|
this.syncLocations = syncLocations || {};
|
|
|
|
this.publishLocations = publishLocations || {};
|
|
|
|
Object.defineProperty(this, 'title', {
|
|
|
|
get: function() {
|
|
|
|
return this._title;
|
|
|
|
},
|
|
|
|
set: function(title) {
|
|
|
|
this._title = title;
|
|
|
|
localStorage[this.fileIndex + ".title"] = title;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Object.defineProperty(this, 'content', {
|
|
|
|
get: function() {
|
|
|
|
return localStorage[this.fileIndex + ".content"];
|
|
|
|
},
|
|
|
|
set: function(content) {
|
|
|
|
localStorage[this.fileIndex + ".content"] = content;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Object.defineProperty(this, 'editorScrollTop', {
|
|
|
|
get: function() {
|
|
|
|
return this._editorScrollTop;
|
|
|
|
},
|
|
|
|
set: function(editorScrollTop) {
|
|
|
|
this._editorScrollTop = editorScrollTop;
|
|
|
|
localStorage[this.fileIndex + ".editorScrollTop"] = editorScrollTop;
|
|
|
|
}
|
|
|
|
});
|
2013-09-09 00:08:55 +00:00
|
|
|
Object.defineProperty(this, 'editorSelectRange', {
|
2013-06-16 10:47:45 +00:00
|
|
|
get: function() {
|
2013-09-09 00:08:55 +00:00
|
|
|
return this._editorSelectRange;
|
2013-06-16 10:47:45 +00:00
|
|
|
},
|
2013-09-09 00:08:55 +00:00
|
|
|
set: function(range) {
|
|
|
|
this._editorSelectRange = range;
|
|
|
|
localStorage[this.fileIndex + ".editorSelectRange"] = [
|
|
|
|
range.start.row,
|
|
|
|
range.start.column,
|
|
|
|
range.end.row,
|
|
|
|
range.end.column
|
|
|
|
].join(';');
|
2013-06-16 10:47:45 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
Object.defineProperty(this, 'previewScrollTop', {
|
|
|
|
get: function() {
|
|
|
|
return this._previewScrollTop;
|
|
|
|
},
|
|
|
|
set: function(previewScrollTop) {
|
|
|
|
this._previewScrollTop = previewScrollTop;
|
|
|
|
localStorage[this.fileIndex + ".previewScrollTop"] = previewScrollTop;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
Object.defineProperty(this, 'selectTime', {
|
|
|
|
get: function() {
|
|
|
|
return this._selectTime;
|
|
|
|
},
|
|
|
|
set: function(selectTime) {
|
|
|
|
this._selectTime = selectTime;
|
|
|
|
localStorage[this.fileIndex + ".selectTime"] = selectTime;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2013-09-09 00:08:55 +00:00
|
|
|
|
2013-06-16 10:47:45 +00:00
|
|
|
FileDescriptor.prototype.addSyncLocation = function(syncAttributes) {
|
|
|
|
utils.storeAttributes(syncAttributes);
|
|
|
|
utils.appendIndexToArray(this.fileIndex + ".sync", syncAttributes.syncIndex);
|
|
|
|
this.syncLocations[syncAttributes.syncIndex] = syncAttributes;
|
|
|
|
};
|
2013-09-09 00:08:55 +00:00
|
|
|
|
2013-06-16 10:47:45 +00:00
|
|
|
FileDescriptor.prototype.removeSyncLocation = function(syncAttributes) {
|
|
|
|
utils.removeIndexFromArray(this.fileIndex + ".sync", syncAttributes.syncIndex);
|
|
|
|
delete this.syncLocations[syncAttributes.syncIndex];
|
|
|
|
localStorage.removeItem(syncAttributes.syncIndex);
|
|
|
|
};
|
2013-09-09 00:08:55 +00:00
|
|
|
|
2013-06-16 10:47:45 +00:00
|
|
|
FileDescriptor.prototype.addPublishLocation = function(publishAttributes) {
|
|
|
|
utils.storeAttributes(publishAttributes);
|
|
|
|
utils.appendIndexToArray(this.fileIndex + ".publish", publishAttributes.publishIndex);
|
|
|
|
this.publishLocations[publishAttributes.publishIndex] = publishAttributes;
|
|
|
|
};
|
2013-09-09 00:08:55 +00:00
|
|
|
|
2013-06-16 10:47:45 +00:00
|
|
|
FileDescriptor.prototype.removePublishLocation = function(publishAttributes) {
|
|
|
|
utils.removeIndexFromArray(this.fileIndex + ".publish", publishAttributes.publishIndex);
|
|
|
|
delete this.publishLocations[publishAttributes.publishIndex];
|
|
|
|
localStorage.removeItem(publishAttributes.publishIndex);
|
|
|
|
};
|
2013-09-09 00:08:55 +00:00
|
|
|
|
2013-08-11 00:52:05 +00:00
|
|
|
FileDescriptor.prototype.composeTitle = function() {
|
|
|
|
var result = [];
|
2013-10-24 22:02:03 +00:00
|
|
|
_.chain(this.syncLocations).sortBy(function(attributes) {
|
2013-10-24 20:57:42 +00:00
|
|
|
return attributes.provider.providerId;
|
|
|
|
}).each(function(attributes) {
|
|
|
|
var classes = 'icon-provider-' + attributes.provider.providerId;
|
|
|
|
attributes.isRealtime === true && (classes += ' realtime');
|
2013-10-24 22:02:03 +00:00
|
|
|
result.push('<i class="' + classes + '"></i>');
|
2013-10-24 20:57:42 +00:00
|
|
|
});
|
2013-10-24 22:02:03 +00:00
|
|
|
if(_.size(this.syncLocations) !== 0) {
|
|
|
|
result.push('<i class="icon-refresh title-icon-category"></i>');
|
2013-10-24 20:57:42 +00:00
|
|
|
}
|
2013-10-24 22:02:03 +00:00
|
|
|
_.chain(this.publishLocations).sortBy(function(attributes) {
|
2013-08-11 00:52:05 +00:00
|
|
|
return attributes.provider.providerId;
|
|
|
|
}).each(function(attributes) {
|
|
|
|
var classes = 'icon-provider-' + attributes.provider.providerId;
|
2013-10-24 20:57:42 +00:00
|
|
|
attributes.isRealtime === true && (classes += ' realtime');
|
2013-10-24 22:02:03 +00:00
|
|
|
result.push('<i class="' + classes + '"></i>');
|
2013-08-11 00:52:05 +00:00
|
|
|
});
|
2013-10-24 22:02:03 +00:00
|
|
|
if(_.size(this.publishLocations) !== 0) {
|
|
|
|
result.push('<i class="icon-share title-icon-category"></i>');
|
2013-10-24 20:57:42 +00:00
|
|
|
}
|
2013-08-11 00:52:05 +00:00
|
|
|
result.push(this.title);
|
|
|
|
return result.join('');
|
|
|
|
};
|
2013-09-09 00:08:55 +00:00
|
|
|
|
2013-06-16 10:47:45 +00:00
|
|
|
return FileDescriptor;
|
|
|
|
});
|