blob: 41b5b2ee6a9a4e1d0debf1cee13f1b9a0f7a7399 [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="/ui/side_panel/side_panel.html">
<link rel="import" href="/model/comment_box_annotation.html">
<link rel="import" href="/ui/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.ui.e.drive.getDriveFileId(),
'revisionId': 'head'
});
request.execute(function(resp) {
var anchorObject = {};
anchorObject[tr.ui.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.ui.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.ui.e.drive.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.ui.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.ui.e.drive.getDriveFileId(),
'resource': {'content': body}
});
request.execute(function(resp) {
self.updateComments();
});
});
}
};
return {
DefaultCommentProvider: DefaultCommentProvider
};
});
</script>