Skip to content

Commit

Permalink
Merge "Partial-Bug: #1537225 Fixed delete in config db using model to…
Browse files Browse the repository at this point in the history
… show proper errors." into R3.0
  • Loading branch information
Zuul authored and opencontrail-ci-admin committed Feb 22, 2016
2 parents c2475ec + 393ec47 commit 687e2d8
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 62 deletions.
6 changes: 6 additions & 0 deletions webroot/common/ui/js/controller.labels.js
Expand Up @@ -973,6 +973,12 @@ define([
this.CDB_TITLE_FQ_TABLE = "FQ Name Table";
this.CDB_TITLE_UUID_TABLE = "UUID Name Table";
this.CDB_TITLE_SHARED_TABLE = "Shared Name Table";
this.CDB_TITLE_DELETE_RECORD = "Delete Record";
this.CDB_TMPL_DELETE_RECORD = "cdb-delete-template";
this.CDB_DELETE_MODAL_ID_ = "delete-cdb";

this.CDB_LABEL_KEY_VALUES = "keyvalues";
this.CDB_LABEL_KEY = "keys";
//Config DB Labels - End

/* Service Appliance */
Expand Down
41 changes: 41 additions & 0 deletions webroot/setting/configdb/ui/js/models/ConfigDatabaseModel.js
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
*/

define([
'underscore',
'contrail-model'
], function (_, ContrailModel) {
var ConfigDatabaseModel = ContrailModel.extend({

deleteRecord: function (checkedRow, callbackObj, type) {
var ajaxConfig = {}, that = this, url;

if (type == ctwc.DELETE_KEY_TYPE) {
url = "/api/query/cassandra/key/" + checkedRow.table + "/" + checkedRow.key;
} else if (type == ctwc.DELETE_KEY_VALUE_TYPE) {
url = "/api/query/cassandra/value/" + checkedRow.table + "/" + checkedRow.key + "/" + checkedRow.keyvalue;
}

ajaxConfig.type = "DELETE";
ajaxConfig.url = url;

contrail.ajaxHandler(ajaxConfig, function () {
if (contrail.checkIfFunction(callbackObj.init)) {
callbackObj.init();
}
}, function (response) {
if (contrail.checkIfFunction(callbackObj.success)) {
callbackObj.success();
}
}, function (error) {
console.log(error);
if (contrail.checkIfFunction(callbackObj.error)) {
callbackObj.error(error);
}
});
},
validations : {}
});
return ConfigDatabaseModel;
});
55 changes: 55 additions & 0 deletions webroot/setting/configdb/ui/js/views/ConfigDatabaseActionView.js
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
*/

define([
'underscore',
'contrail-view',
'knockback'
], function (_, ContrailView, Knockback) {

var modalId = ctwl.CDB_DELETE_MODAL_ID_,
ConfigDatabaseActionView = ContrailView.extend({

renderDeleteRecord: function (options) {
var textTemplate = contrail.getTemplate4Id(ctwl.CDB_TMPL_DELETE_RECORD),
elId = 'deleteRecord',
self = this,
checkedRows = options['checkedRows'],
recordsToBeDeleted = {'elementId': elId, 'checkedRows': checkedRows};

cowu.createModal({
'modalId' : modalId,
'className': 'modal-700',
'title' : options['title'],
'btnName' : 'Confirm',
'body' : textTemplate(recordsToBeDeleted),
'onSave' : function () {
self.model.deleteRecord(options['checkedRows'], {
init : function () {
self.model.showErrorAttr(elId, false);
cowu.enableModalLoading(modalId);
},
success: function () {
options['callback']();
$("#" + modalId).modal('hide');
},
error : function (error) {
cowu.disableModalLoading(modalId, function () {
self.model.showErrorAttr(elId, error.responseText);
});
}
}, options['type']);
},
'onCancel' : function () {
$("#" + modalId).modal('hide');
}
});

self.model.showErrorAttr(elId, false);
Knockback.applyBindings(this.model, document.getElementById(modalId));
kbValidation.bind(this);
},
});
return ConfigDatabaseActionView;
});
90 changes: 28 additions & 62 deletions webroot/setting/configdb/ui/js/views/ConfigDatabaseView.js
Expand Up @@ -4,8 +4,10 @@

define([
'underscore',
'contrail-view'
], function (_, ContrailView) {
'contrail-view',
'setting/configdb/ui/js/models/ConfigDatabaseModel',
'setting/configdb/ui/js/views/ConfigDatabaseActionView'
], function (_, ContrailView, ConfigDatabaseModel, ConfigDatabaseActionView) {
var ConfigDatabaseView = ContrailView.extend({
el: $(contentContainer),

Expand Down Expand Up @@ -345,7 +347,7 @@ define([
forceFitColumns: true,
actionCell: function (dc) {
if (gridConfig.actionCell && globalObj['configDBEditEnabled']) {
return getActionCog(gridConfig.columnName, gridId);
return getRowActionConfig(gridConfig.columnName, gridId);
} else {
return [];
}
Expand Down Expand Up @@ -385,66 +387,30 @@ define([
}
};

function getActionCog(columnName, gridId){
return [{
title: 'Delete',
iconClass: 'icon-trash',
onClick: function(rowIndex){
var selectedRow = $('#' + gridId).data('contrailGrid')._dataView.getItem(rowIndex);
if(columnName === "keys"){
createModalForDelete(selectedRow, "delete-key");
}else if(columnName === "keyvalues"){
createModalForDelete(selectedRow, "delete-key-value");
}
}
}];
};

function createModalForDelete (selectedRow, type){
var textTemplate = '', modalId = "delete-cdb",
callbackObj = {
init: function () {
cowu.enableModalLoading(modalId);
},
success: function () {
$("#" + modalId).modal('hide');
},
error: function (error) {
cowu.disableModalLoading(modalId, function () {});
}
};

if( (contrail.checkIfExist(selectedRow.keyvalue)) && (type == ctwc.DELETE_KEY_VALUE_TYPE) ){
textTemplate = '<div>Are you sure you want to delete <b>' + selectedRow.keyvalue + '</b> ?</div>';
} else if ((contrail.checkIfExist(selectedRow.key)) && (type == ctwc.DELETE_KEY_TYPE)) {
textTemplate = '<div>Are you sure you want to delete <b>' + selectedRow.key + '</b> ?</div>';
}
function getRowActionConfig (columnName, gridId) {
var type = '',
rowActionConfig = [
ctwgc.getDeleteAction(function (rowIndex) {
var dataItem = $('#' + gridId).data('contrailGrid')._dataView.getItem(rowIndex),
configDatabaseModel = new ConfigDatabaseModel(dataItem),
checkedRow = dataItem, title = ctwl.CDB_TITLE_DELETE_RECORD,
configDatabaseActionView = new ConfigDatabaseActionView();

cowu.createModal({'modalId': modalId , 'className': 'modal-700', 'title': "Delete ", 'btnName': 'Confirm', 'body': textTemplate, 'onSave': function () {
var url, ajaxConfig = {};

if (type == ctwc.DELETE_KEY_TYPE) {
url = "/api/query/cassandra/key/" + selectedRow.table + "/" + selectedRow.key;
} else if (type == ctwc.DELETE_KEY_VALUE_TYPE) {
url = "/api/query/cassandra/value/" + selectedRow.table + "/" + selectedRow.key + "/" + selectedRow.keyvalue;
}

ajaxConfig.type = "DELETE";
ajaxConfig.url = url;

contrail.ajaxHandler(ajaxConfig, function (response) {
if (contrail.checkIfFunction(callbackObj.success)) {
callbackObj.success();
}
}, function (error) {
if (contrail.checkIfFunction(callbackObj.error)) {
callbackObj.error(error);
}
});

}, 'onCancel': function () {
$("#" + modalId).modal('hide');
}});
configDatabaseActionView.model = configDatabaseModel;
if (columnName === ctwl.CDB_LABEL_KEY) {
type = "delete-key";
} else if (columnName === ctwl.CDB_LABEL_KEY_VALUES) {
type = "delete-key-value";
}
configDatabaseActionView.renderDeleteRecord({
"title": title, "type": type, checkedRows: checkedRow, callback: function () {
var dataView = $('#' + gridId).data("contrailGrid")._dataView;
dataView.refreshData();
}
});
})
];
return rowActionConfig;
};

return ConfigDatabaseView;
Expand Down

0 comments on commit 687e2d8

Please sign in to comment.