|
|
|
@ -60,6 +60,9 @@ define(function(require) { |
|
|
|
render: function(container) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
console.log("STORAGES:"); |
|
|
|
console.log(self.storages); |
|
|
|
|
|
|
|
monster.pub('storage.fetchStorages', { |
|
|
|
storages: self.storages, |
|
|
|
callback: function (args) { |
|
|
|
@ -119,7 +122,10 @@ define(function(require) { |
|
|
|
self.getStorage(function(data) { |
|
|
|
var storagesData = self.storageManagerFormatData(data); |
|
|
|
for (var i = 0, len = storagesData.length; i < len; i++) { |
|
|
|
storagesData[i].logo = self.storages[storagesData[i].type].getLogo() |
|
|
|
//storagesData[i].logo = self.storages[storagesData[i].type].getLogo()
|
|
|
|
var storageType = storagesData[i].type; |
|
|
|
|
|
|
|
storagesData[i].logo = self.storages[storageType].getLogo() |
|
|
|
} |
|
|
|
|
|
|
|
log('Storages List:'); |
|
|
|
@ -194,6 +200,31 @@ define(function(require) { |
|
|
|
}); |
|
|
|
}, |
|
|
|
|
|
|
|
formatAttachmentSettings: function(storageData) { |
|
|
|
var type = ""; |
|
|
|
var attachments = storageData.attachments; |
|
|
|
|
|
|
|
if(storageData.hasOwnProperty('connections')) { //type is couchdb
|
|
|
|
attachments = storageData.connections; |
|
|
|
type = "couchdb"; |
|
|
|
} |
|
|
|
|
|
|
|
var attachments = storageData.attachments; |
|
|
|
for(var i in attachments) if(attachments.hasOwnProperty(i)) { |
|
|
|
var thisItem = attachments[i]; |
|
|
|
var settings = thisItem.settings; |
|
|
|
if (thisItem.settings && thisItem.settings.port) { |
|
|
|
thisItem.settings.port = Number(thisItem.settings.port); |
|
|
|
} else { |
|
|
|
thisItem.settings.port = 443; |
|
|
|
if (type == "couchdb") thisItem.settings.port = 5984; |
|
|
|
} |
|
|
|
attachments[i] = thisItem; |
|
|
|
}; |
|
|
|
storageData.attachments = attachments; |
|
|
|
return storageData; |
|
|
|
}, |
|
|
|
|
|
|
|
storageManagerUpdateStorage: function(storageData, callback) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
@ -207,7 +238,7 @@ define(function(require) { |
|
|
|
data: { |
|
|
|
accountId: self.accountId, |
|
|
|
removeMetadataAPI: true, // or generateError: false
|
|
|
|
data: storageData |
|
|
|
data: self.formatAttachmentSettings(storageData) |
|
|
|
}, |
|
|
|
success: function(data, status) { |
|
|
|
if(typeof(callback) === 'function') { |
|
|
|
@ -237,7 +268,7 @@ define(function(require) { |
|
|
|
data: { |
|
|
|
accountId: self.accountId, |
|
|
|
removeMetadataAPI: true, // or generateError: false
|
|
|
|
data: storageData |
|
|
|
data: self.formatAttachmentSettings(storageData) |
|
|
|
}, |
|
|
|
success: function(data, status) { |
|
|
|
if(typeof(callback) === 'function') { |
|
|
|
@ -256,20 +287,59 @@ define(function(require) { |
|
|
|
|
|
|
|
storageManagerFormatData: function(data) { |
|
|
|
var activeStorageId = null; |
|
|
|
var storageType = ""; |
|
|
|
try { |
|
|
|
//activeStorageId = data.plan.modb.connection; //.handler;
|
|
|
|
if(data && data.hasOwnProperty('plan') && data.plan.hasOwnProperty('modb') && data.plan.modb.hasOwnProperty('connection') ) { |
|
|
|
activeStorageId = data.plan.modb.connection; //.handler;
|
|
|
|
storageType = "couchdb"; |
|
|
|
} else { |
|
|
|
activeStorageId = data.plan.modb.types.call_recording.attachments.handler; |
|
|
|
} |
|
|
|
} catch(e) { |
|
|
|
log('Active storage not found'); |
|
|
|
} |
|
|
|
var itemData; |
|
|
|
var storagesList = []; |
|
|
|
if (storageType == "couchdb" && data && data.hasOwnProperty('connections') && Object.keys(data.connections).length > 0) { |
|
|
|
var connections = data.connections; |
|
|
|
for(var i in connections) if(connections.hasOwnProperty(i)) { |
|
|
|
itemData = { |
|
|
|
id: i, |
|
|
|
// type: connections[i].handler,
|
|
|
|
// type: connections[i],
|
|
|
|
type: storageType, //"couchdb"
|
|
|
|
name: connections[i].name, |
|
|
|
settings: connections[i].settings, |
|
|
|
isActive: false |
|
|
|
}; |
|
|
|
|
|
|
|
if(activeStorageId && itemData.id === activeStorageId) { |
|
|
|
itemData.isActive = true; |
|
|
|
} |
|
|
|
storagesList.push(itemData) |
|
|
|
} |
|
|
|
} |
|
|
|
if(data && data.hasOwnProperty('attachments') && Object.keys(data.attachments).length > 0) { |
|
|
|
var attachments = data.attachments; |
|
|
|
|
|
|
|
for(var i in attachments) if(attachments.hasOwnProperty(i)) { |
|
|
|
var storageType = attachments[i].handler; |
|
|
|
var settings = attachments[i].settings; |
|
|
|
//get custom s3 type by checking if URL is not AWS
|
|
|
|
if (storageType == "s3" |
|
|
|
&& ( |
|
|
|
(settings.hasOwnProperty('host') && settings.host != "s3.amazonaws.com" && settings.host != "") |
|
|
|
|| (settings.hasOwnProperty('port') && settings.port != "443" && settings.port != 443 && settings.port != "") |
|
|
|
) |
|
|
|
) { |
|
|
|
storageType = "custom_s3"; |
|
|
|
} |
|
|
|
|
|
|
|
itemData = { |
|
|
|
id: i, |
|
|
|
type: attachments[i].handler, |
|
|
|
//type: attachments[i].handler,
|
|
|
|
type: storageType, |
|
|
|
name: attachments[i].name, |
|
|
|
settings: attachments[i].settings, |
|
|
|
isActive: false |
|
|
|
@ -301,8 +371,10 @@ define(function(require) { |
|
|
|
.find('.js-item-settings-wrapper') |
|
|
|
.hide(); |
|
|
|
|
|
|
|
if(data.attachments.hasOwnProperty(uuid)) { |
|
|
|
if(data.attachments && data.attachments.hasOwnProperty(uuid)) { |
|
|
|
var storageData = data.attachments[uuid]; |
|
|
|
} else if(data.connections && data.connections.hasOwnProperty(uuid)) { |
|
|
|
var storageData = data.connections[uuid]; |
|
|
|
} |
|
|
|
|
|
|
|
var template = self.getTemplate({ |
|
|
|
@ -360,7 +432,8 @@ define(function(require) { |
|
|
|
if(isAlreadyActive) { |
|
|
|
self.storageManagerShowMessage(self.i18n.active().storage.alreadyActiveMessage, 'warning') |
|
|
|
} else { |
|
|
|
self.storageManagerSetDefaultStorage(uuid); |
|
|
|
var storageType = $(this).closest('.js-storage-item').data('type'); |
|
|
|
self.storageManagerSetDefaultStorage(uuid, storageType); |
|
|
|
} |
|
|
|
}); |
|
|
|
}, |
|
|
|
@ -421,7 +494,7 @@ define(function(require) { |
|
|
|
}; |
|
|
|
|
|
|
|
if(isNeedSetDefault) { |
|
|
|
self.storageManagerSetDefaultStorage(newUuid, function () { |
|
|
|
self.storageManagerSetDefaultStorage(newUuid, typeKeyword, function () { |
|
|
|
self.storageManagerRender(renderArgs); |
|
|
|
}); |
|
|
|
} else { |
|
|
|
@ -449,22 +522,60 @@ define(function(require) { |
|
|
|
} |
|
|
|
|
|
|
|
if(storageKeyword && self.storages.hasOwnProperty(storageKeyword)) { |
|
|
|
if (storageKeyword == "couchdb") { |
|
|
|
storageData["connections"] = {}; |
|
|
|
data.settings.port = eval(data.settings.port); |
|
|
|
storageData.connections[uuid] = data; |
|
|
|
} else { |
|
|
|
storageData.attachments[uuid] = data; |
|
|
|
} |
|
|
|
return storageData; |
|
|
|
} else { |
|
|
|
monster.ui.alert('Please install storage correctly (' + storageKeyword + ')'); |
|
|
|
} |
|
|
|
}, |
|
|
|
|
|
|
|
storageManagerSetDefaultStorage: function(uuid, callback) { |
|
|
|
storageManagerSetDefaultStorage: function(uuid, storageType, callback) { |
|
|
|
var self = this; |
|
|
|
|
|
|
|
if(!monster.util.isAdmin()) { |
|
|
|
log('Permission error. Use admin account for change storage settings'); |
|
|
|
return; |
|
|
|
} |
|
|
|
var newData = {}; |
|
|
|
if (storageType == "couchdb") { |
|
|
|
newData = { |
|
|
|
plan: { |
|
|
|
modb: { |
|
|
|
connection: uuid, |
|
|
|
types: { |
|
|
|
call_recording: { |
|
|
|
database:{ |
|
|
|
create_options:{} |
|
|
|
} |
|
|
|
}, |
|
|
|
mailbox_message: { |
|
|
|
database:{ |
|
|
|
create_options:{} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// account: {
|
|
|
|
// types: {
|
|
|
|
// media: {
|
|
|
|
// database:{
|
|
|
|
// create_options:{}
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// },
|
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
var newData = { |
|
|
|
} else { |
|
|
|
newData = { |
|
|
|
plan: { |
|
|
|
modb: { |
|
|
|
types: { |
|
|
|
@ -491,7 +602,7 @@ define(function(require) { |
|
|
|
}, |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
self.storageManagerPatchStorage(newData, function(data) { |
|
|
|
$('#storage_manager_wrapper').find('.js-storage-item') |
|
|
|
@ -547,12 +658,19 @@ define(function(require) { |
|
|
|
|
|
|
|
self.getStorage(function(storagesData) { |
|
|
|
var resultData = {}; |
|
|
|
if(storagesData.hasOwnProperty('connections')) { |
|
|
|
resultData.connections = storagesData.connections; |
|
|
|
} |
|
|
|
if(storagesData.hasOwnProperty('attachments')) { |
|
|
|
resultData.attachments = storagesData.attachments; |
|
|
|
} |
|
|
|
if(storagesData.hasOwnProperty('plan')) { |
|
|
|
resultData.plan = storagesData.plan; |
|
|
|
} |
|
|
|
if(resultData.connections && resultData.connections.hasOwnProperty(uuid)) { |
|
|
|
resultData.attachments = {}; |
|
|
|
delete resultData.connections[uuid]; |
|
|
|
} |
|
|
|
|
|
|
|
if(resultData.attachments && resultData.attachments.hasOwnProperty(uuid)) { |
|
|
|
delete resultData.attachments[uuid]; |
|
|
|
@ -561,6 +679,8 @@ define(function(require) { |
|
|
|
try { |
|
|
|
if(resultData.plan.modb.types.call_recording.attachments.handler === uuid) { |
|
|
|
resultData.plan = {}; |
|
|
|
} else if(resultData.plan.modb.types.call_recording.connection === uuid) { |
|
|
|
resultData.plan = {}; |
|
|
|
} |
|
|
|
} catch (e) {} |
|
|
|
|
|
|
|
|