var app = angular.module('mailboxBrowser', ['angularTreeview']);
// --- connection variables ---
var host = '<your_host_here>'; var port = '<your_port_here>';
// ----------------------------
// this controller kicks off the chain of 'GET' API calls to get the data from the server app.controller('treeCtrl', function($scope, $http) {
var waitCount = 1; var mailboxId = '1'; $http.defaults.useXDomain = true; $scope.nodeValidityMessage = "abc";
$scope.treedata = [{ // initialize the first node with the root mailbox 'label' : '/', 'id' : '1', 'children' : [], 'type': 'mailbox', 'path' : '/' }];
$scope.evaluateType = function() { console.log('entered'); if ($scope.currentNode.type === 'mailbox') { $scope.nodeValidityMessage = ''; } else { $scope.nodeValidityMessage = 'The selected node is not a valid destination, ' +
'since it's a file."; } }
getContents($http, $scope.treedata[0]); initializeDropzone();
});
// lists the contents of a node function getContents(http, node) {
var parentMailboxId = node.id.toString();
http({ url: 'http://' + host + ':' + port + '/mailbox/svc/mailboxcontents/?parentMailboxId=' + parentMailboxId,
method: 'GET', headers: { 'Accept':'application/json', 'Content-Type':'application/json', 'Authorization':'Basic YWRtaW46cGFzc3dvcmQ=' } }).success(function(data, status, headers, config) { node.children = new Array(data.length); // create empty slots for the children for (var i=0; i < data.length; i++) { var item = data[i]; node.children[i] = new Node(item); if (item.type === 'mailbox'){ getContents(http, node.children[i]); } if (node.label === '/') {
// the root level already has a slash, so there's no need to add it node.children[i].path = node.path + node.children[i].label; } else {
// prepend a slash to this node's label node.children[i].path = node.path + '/' + node.children[i].label; } } }).error(function(data, status, headers, config) { console.log('error retrieving messages for mailbox with id ' + parentMailboxId); }); }
// creates a new node from a back-end item var Node = function(item) { this.label = item.name; this.id = item.id.toString(); this.type = item.type; this.children = []; }
// sets the parameters needed to perform file upload var initializeDropzone = function() { var myDropzone = new Dropzone(".uploadpanel", {
// "batchs" is misspelled on purpose due to framework limitations - do not correct url: 'http://' + host + ':' + port + '/mailbox/svc/messagebatchs/', method: 'POST', headers: { 'Authorization':'Basic YWRtaW46cGFzc3dvcmQ=', 'Cache-Control': '' }, uploadMultiple: true, parallelUploads: 1000 }); }
|