blob: 6e13c79358db323bf7222a2cc315c0abc9749a9e [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/core/side_panel/side_panel.html">
<link rel="import" href="/model/comment_box_annotation.html">
<link rel="import" href="/extras/drive/comments_side_panel.html">
<script>
'use strict';
(function() {
function addDriveCommentWithUIState_(text, uiState) {
gapi.client.load('drive', 'v2', function() {
var request = gapi.client.drive.revisions.get({
'fileId': tr.e.drive.getDriveFileId(),
'revisionId': 'head'
});
request.execute(function(resp) {
var anchorObject = {};
anchorObject[tr.e.drive.constants.ANCHOR_NAME] = uiState;
var anchor = {
'r': resp.id,
'a': [anchorObject]
};
anchor = JSON.stringify(anchor);
gapi.client.load('drive', 'v2', function() {
var request = gapi.client.drive.comments.insert({
'fileId': tr.e.drive.getDriveFileId(),
'resource': {'content': text, 'anchor': anchor}
});
request.execute();
});
});
});
};
function onCommentWithUIState(e) {
addDriveCommentWithUIState_(e.detail.name, e.detail.location);
};
document.addEventListener('commentWithUIState',
onCommentWithUIState.bind(this));
}());
tr.exportTo('tr.e.analysis', function() {
function DefaultCommentProvider() { }
DefaultCommentProvider.prototype = {
attachToElement: function(attachedElement) {
this.attachedElement_ = attachedElement;
this.commentsCheckTimer_ = setTimeout(this.checkForComments_.bind(this),
5000);
},
detachFromElement: function() {
clearTimeout(this.commentsCheckTimer_);
},
checkForComments_: function() {
this.updateComments();
this.commentsCheckTimer_ = setTimeout(this.checkForComments_.bind(this),
5000);
},
updateComments: function() {
var self = this;
gapi.client.load('drive', 'v2', function() {
var request = gapi.client.drive.comments.list({
'fileId': tr.e.drive.getDriveFileId()
});
request.execute(function(results) {
self.attachedElement_.comments_ = results.items;
});
});
},
addComment: function(body) {
var self = this;
gapi.client.load('drive', 'v2', function() {
var request = gapi.client.drive.comments.insert({
'fileId': tr.e.drive.getDriveFileId(),
'resource': {'content': body}
});
request.execute(function(resp) {
self.updateComments();
});
});
}
};
return {
DefaultCommentProvider: DefaultCommentProvider
};
});
</script>