| <!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="/core/trace_model/comment_box_annotation.html"> |
| |
| <link rel="import" href="/extras/drive/side_panel_comments.html"> |
| |
| <script> |
| 'use strict'; |
| |
| (function() { |
| function addDriveCommentWithUIState_(text, uiState) { |
| gapi.client.load('drive', 'v2', function() { |
| var request = gapi.client.drive.revisions.get({ |
| 'fileId': tv.e.drive.getDriveFileId(), |
| 'revisionId': 'head' |
| }); |
| request.execute(function(resp) { |
| var anchorObject = {}; |
| anchorObject[tv.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': tv.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)); |
| }()); |
| |
| tv.exportTo('tv.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': tv.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': tv.e.drive.getDriveFileId(), |
| 'resource': {'content': body} |
| }); |
| request.execute(function(resp) { |
| self.updateComments(); |
| }); |
| }); |
| } |
| }; |
| |
| return { |
| DefaultCommentProvider: DefaultCommentProvider |
| }; |
| }); |
| |
| </script> |