Commit 69d403e8 by kevalbhatt

ATLAS-3636 : [Namespace-UI] Issues/ambiguous error messages while adding a new…

ATLAS-3636 : [Namespace-UI] Issues/ambiguous error messages while adding a new attribute in a Namespace
parent 43c134dd
...@@ -228,7 +228,6 @@ pre { ...@@ -228,7 +228,6 @@ pre {
.custom-col-1, .custom-col-1,
.custom-col-2 { .custom-col-2 {
vertical-align: top; vertical-align: top;
display: inline-block;
textarea { textarea {
resize: vertical; resize: vertical;
...@@ -254,8 +253,13 @@ pre { ...@@ -254,8 +253,13 @@ pre {
.custom-col-2 { .custom-col-2 {
text-align: center; text-align: center;
width: 17%; width: 17%;
margin-left: 1%; padding-left: 1%;
margin-bottom: 10px; margin-bottom: 10px;
&>button {
padding: 7px 10px;
margin-bottom: 10px;
}
} }
} }
} }
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
width: 35%; width: 35%;
} }
word-break: break-all; word-break: break-word;
} }
} }
......
...@@ -15,21 +15,25 @@ ...@@ -15,21 +15,25 @@
* limitations under the License. * limitations under the License.
--> -->
{{#ifCond model "has" "isNew"}} {{#ifCond model "has" "isNew"}}
<td class="custom-col-1"> <table class="custom-table" style="font-weight: 100;">
{{{callmyfunction getNamespaceDroupdown nameSpaceCollection}}} <tr class="custom-tr">
</td> <td class="custom-col-1">
<td class="custom-col-0"> : </td> {{{callmyfunction getNamespaceDroupdown nameSpaceCollection}}}
<td class="custom-col-1" data-id="value"> </td>
<input type="text" data-key disabled class="form-control"> <td class="custom-col-0"> : </td>
</td> <td class="custom-col-1" data-id="value">
<td class="custom-col-2 btn-group"> <input type="text" data-key disabled class="form-control">
<button class="btn btn-default btn-sm" data-id="deleteItem"> </td>
<i class="fa fa-minus"> </i> <td class="custom-col-2 btn-group">
</button> <button class="btn btn-default btn-sm" data-id="deleteItem">
<button class="btn btn-default btn-sm" data-id="addItem"> <i class="fa fa-minus"> </i>
<i class="fa fa-plus"> </i> </button>
</button> <button class="btn btn-default btn-sm" data-id="addItem">
</td> <i class="fa fa-plus"> </i>
</button>
</td>
</tr>
</table>
{{else}} {{else}}
<hr /> <hr />
<ul class="namespace-tree-parent"> <ul class="namespace-tree-parent">
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
</div> </div>
</div> </div>
<div class="panel-actions"> <div class="panel-actions">
<button class="btn btn-action btn-sm" title="" data-id="addNameSpace">Add</button> <button class="btn btn-action btn-sm" data-id="addNameSpace">Add</button>
<button class="btn btn-action btn-sm" style="display: none;" data-id="saveNameSpace">Save</button> <button class="btn btn-action btn-sm" style="display: none;" data-id="saveNameSpace">Save</button>
<button class="btn btn-action btn-sm" style="display: none;" data-id="cancel">Cancel</button> <button class="btn btn-action btn-sm" style="display: none;" data-id="cancel">Cancel</button>
</div> </div>
...@@ -35,9 +35,7 @@ ...@@ -35,9 +35,7 @@
<div class="form-group"> <div class="form-group">
<a href="javascript:void(0)" class="btn btn-action btn-sm" data-id="addItem" data-type="addAttrButton">Add New Attribute</a> <a href="javascript:void(0)" class="btn btn-action btn-sm" data-id="addItem" data-type="addAttrButton">Add New Attribute</a>
</div> </div>
<table class="custom-table"> <ul class="namespace-tree-parent" data-id="itemView"></ul>
<tbody data-id="itemView"></tbody>
</table>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
--> -->
<div class="form-group clearfix namespace-attr"> <div id="{{modalID}}" class="form-group clearfix namespace-attr">
<div class="form-group"> <div class="form-group">
<div class="col-sm-12 attributePlusData " align="right"> <div class="col-sm-12 attributePlusData " align="right">
<button type="button" class="btn btn-danger btn-sm closeInput" data-id="close"><i class="fa fa-times"></i></button> <button type="button" class="btn btn-danger btn-sm closeInput" data-id="close"><i class="fa fa-times"></i></button>
......
...@@ -38,8 +38,8 @@ define(['require', ...@@ -38,8 +38,8 @@ define(['require',
model: this.model.toJSON() model: this.model.toJSON()
} }
}, },
tagName: 'tr', tagName: 'li',
className: "custom-tr", className: "namespace-tree-child",
/** Layout sub regions */ /** Layout sub regions */
regions: {}, regions: {},
...@@ -142,9 +142,10 @@ define(['require', ...@@ -142,9 +142,10 @@ define(['require',
}); });
} }
}, },
getAttrElement: function(options) { getAttrElement: function(opt) {
var that = this, var that = this,
returnEL = "N/A"; returnEL = "N/A",
options = $.extend(true, {}, opt);
if (options) { if (options) {
var key = options.key, var key = options.key,
typeName = options.val.typeName || "", typeName = options.val.typeName || "",
...@@ -153,24 +154,21 @@ define(['require', ...@@ -153,24 +154,21 @@ define(['require',
namespace = options.namespace, namespace = options.namespace,
allowOnlyNum = false; allowOnlyNum = false;
var elType = isMultiValued ? "select" : "input"; var elType = isMultiValued ? "select" : "input";
if (!_.isEmpty(val)) { if (!isMultiValued && !_.isEmpty(val)) {
val = _.escape(val); val = _.escape(val);
} }
if (!_.isUndefinedNull(val) && typeName.indexOf("boolean") > -1) { if (!_.isUndefinedNull(val) && typeName.indexOf("boolean") > -1) {
val = String(val); val = String(val);
} }
if (typeName.indexOf("date") > -1) { if (typeName.indexOf("date") > -1) {
if (isMultiValued && val) { if (isMultiValued && val && val.length) {
var dateVlaues = val.split(','); var dateStr = [];
if (dateVlaues.length) { _.each(val, function(selectedDate) {
var dateStr = []; selectedDate = parseInt(selectedDate);
_.each(dateVlaues, function(selectedDate) { dateStr.push(moment(selectedDate).format("MM/DD/YYYY"));
selectedDate = parseInt(selectedDate); });
dateStr.push(moment(selectedDate).format("MM/DD/YYYY")); val = dateStr.join(',');
}); } else if (!isMultiValued && val) {
val = dateStr.join(',');
}
} else if (val) {
val = parseInt(val); val = parseInt(val);
val = moment(val).format("MM/DD/YYYY"); val = moment(val).format("MM/DD/YYYY");
} }
...@@ -199,13 +197,14 @@ define(['require', ...@@ -199,13 +197,14 @@ define(['require',
allowOnlyNum = true; allowOnlyNum = true;
returnEL = '<' + elType + ' data-key="' + key + '" data-namespace="' + namespace + '" data-typename="' + typeName + '" type="number" data-multi="' + isMultiValued + '" data-tags="true" placeholder="Enter Number" class="form-control" ' + (!_.isUndefinedNull(val) ? 'value="' + val + '"' : "") + '></' + elType + '>'; returnEL = '<' + elType + ' data-key="' + key + '" data-namespace="' + namespace + '" data-typename="' + typeName + '" type="number" data-multi="' + isMultiValued + '" data-tags="true" placeholder="Enter Number" class="form-control" ' + (!_.isUndefinedNull(val) ? 'value="' + val + '"' : "") + '></' + elType + '>';
} else if (typeName) { } else if (typeName) {
var modTypeName = typeName;
if (isMultiValued) { if (isMultiValued) {
var multipleType = typeName.match("array<(.*)>"); var multipleType = typeName.match("array<(.*)>");
if (multipleType && multipleType[1]) { if (multipleType && multipleType[1]) {
typeName = multipleType[1]; modTypeName = multipleType[1];
} }
} }
var foundEnumType = this.enumDefCollection.fullCollection.find({ name: typeName }); var foundEnumType = this.enumDefCollection.fullCollection.find({ name: modTypeName });
if (foundEnumType) { if (foundEnumType) {
var enumOptions = ""; var enumOptions = "";
_.forEach(foundEnumType.get("elementDefs"), function(obj) { _.forEach(foundEnumType.get("elementDefs"), function(obj) {
...@@ -214,15 +213,17 @@ define(['require', ...@@ -214,15 +213,17 @@ define(['require',
returnEL = '<select data-key="' + key + '" data-namespace="' + namespace + '" data-typename="' + typeName + '" data-multi="' + isMultiValued + '" >' + enumOptions + '</select>'; returnEL = '<select data-key="' + key + '" data-namespace="' + namespace + '" data-typename="' + typeName + '" data-multi="' + isMultiValued + '" >' + enumOptions + '</select>';
} }
setTimeout(function() { setTimeout(function() {
var selectEl = that.$el.find('.custom-col-1[data-id="value"] select[data-key="' + key + '"]'); if (!isMultiValued) {
selectEl.val((val || "")); var selectEl = that.$el.find('.custom-col-1[data-id="value"] select[data-key="' + key + '"]');
selectEl.select2(); selectEl.val((val || ""));
selectEl.select2();
}
}, 0); }, 0);
} }
if (isMultiValued) { if (isMultiValued) {
setTimeout(function() { setTimeout(function() {
var selectEl = that.$el.find('.custom-col-1[data-id="value"] select[data-key="' + key + '"][data-multi="true"]'); var selectEl = that.$el.find('.custom-col-1[data-id="value"] select[data-key="' + key + '"][data-multi="true"]');
var data = val && val.split(",") || []; var data = val && val.length && (_.isArray(val) ? val : val.split(",")) || [];
if (allowOnlyNum) { if (allowOnlyNum) {
selectEl.parent().addClass("select2_only_number"); selectEl.parent().addClass("select2_only_number");
} }
...@@ -323,7 +324,7 @@ define(['require', ...@@ -323,7 +324,7 @@ define(['require',
'<button class="btn btn-default btn-sm" data-key="' + key + '" data-id="deleteItem">' + '<button class="btn btn-default btn-sm" data-key="' + key + '" data-id="deleteItem">' +
'<i class="fa fa-times"> </i>' + '<i class="fa fa-times"> </i>' +
'</button></td>'; '</button></td>';
trs += "<tr>" + td + "</tr>"; trs += "<tr class='custom-tr'>" + td + "</tr>";
} }
}) })
this.$("[data-id='namespaceTreeChild']").html("<table class='custom-table'>" + trs + "</table>"); this.$("[data-id='namespaceTreeChild']").html("<table class='custom-table'>" + trs + "</table>");
......
...@@ -117,10 +117,8 @@ define([ ...@@ -117,10 +117,8 @@ define([
this.$el.find(".panel-heading").addClass("collapsed"); this.$el.find(".panel-heading").addClass("collapsed");
this.$el.find(".panel-collapse.collapse").removeClass("in"); this.$el.find(".panel-collapse.collapse").removeClass("in");
this.ui.addNameSpace.text("Add"); this.ui.addNameSpace.text("Add");
this.ui.addNameSpace.attr("data-original-title", "Add");
} else { } else {
this.ui.addNameSpace.text("Edit"); this.ui.addNameSpace.text("Edit");
this.ui.addNameSpace.attr("data-original-title", "Edit All");
this.$el.find(".panel-heading").removeClass("collapsed"); this.$el.find(".panel-heading").removeClass("collapsed");
this.$el.find(".panel-collapse.collapse").addClass("in"); this.$el.find(".panel-collapse.collapse").addClass("in");
} }
...@@ -157,8 +155,13 @@ define([ ...@@ -157,8 +155,13 @@ define([
if (!this.validate()) { if (!this.validate()) {
return; return;
} }
var nData = this.generateData();
if (this.actualCollection.length === 0 && _.isEmpty(nData)) {
this.onCancel();
return;
}
this.entityModel.saveNamespaceEntity(this.guid, { this.entityModel.saveNamespaceEntity(this.guid, {
data: JSON.stringify(this.generateData()), data: JSON.stringify(nData),
type: "POST", type: "POST",
success: function(data) { success: function(data) {
Utils.notifySuccess({ Utils.notifySuccess({
......
...@@ -281,17 +281,67 @@ define(['require', ...@@ -281,17 +281,67 @@ define(['require',
return true; return true;
} }
}, },
namespaceAttributes: function(modelEl, obj, elementValues) {
obj.options = {
"applicableEntityTypes": JSON.stringify(modelEl.find(".entityTypeSelector").val()),
"maxStrLength": modelEl.find(".stringLengthVal").val() ? modelEl.find(".stringLengthVal").val() : "0"
};
if (obj.typeName != "string" && obj.typeName != "boolean" && obj.typeName != "byte" && obj.typeName != "short" && obj.typeName != "int" && obj.typeName != "float" && obj.typeName != "double" && obj.typeName != "long" && obj.typeName != "date") {
var enumName = enumDefCollection.fullCollection.findWhere({ name: obj.typeName });
if (enumName) {
var enumDef = enumName.get('elementDefs');
if (enumDef.length === obj.enumValues.length) {
_.each(enumDef, function(enumVal, index) {
if (obj.enumValues.indexOf(enumVal.value) === -1) {
this.isPutCall = true;
};
})
} else {
this.isPutCall = true;
}
} else {
this.isPostCallEnum = true;
}
_.each(obj.enumValues, function(inputEnumVal, index) {
elementValues.push({
"ordinal": index + 1,
"value": inputEnumVal
})
});
}
if (obj.multiValueSelect) {
obj.multiValued = true;
obj.typeName = "array<" + obj.typeName + ">";
}
},
highlightAttrinuteName: function(modelEl, obj) {
Utils.notifyInfo({
content: "Attribute " + obj.name + " already exist"
});
modelEl.find(".attributeInput").css("borderColor", "red");
this.loaderStatus(false);
},
createEnumObject: function(arrayObj, obj, enumVal) {
return arrayObj.push({
"name": obj.typeName,
"elementDefs": enumVal
});
},
onCreateNameSpace: function() { onCreateNameSpace: function() {
var that = this, var that = this,
validate = true, validate = true,
attrNameValidate = true, attrNameValidate = true,
enumValue = true, enumValue = true,
stringValidate = true, stringValidate = true,
isPutCall = false,
isPostCallEnum = false,
enumDefs = [], enumDefs = [],
putEnumDef = []; putEnumDef = [],
attrNames = [],
isvalidName = true;
this.checkLoader = 0; this.checkLoader = 0;
this.isPutCall = false;
this.isPostCallEnum = false;
if (this.validateValues()) { if (this.validateValues()) {
return; return;
...@@ -305,51 +355,22 @@ define(['require', ...@@ -305,51 +355,22 @@ define(['require',
} }
if (attributeObj.length) { if (attributeObj.length) {
_.each(attributeObj, function(obj) { _.each(attributeObj, function(obj) {
var isMultiCheck = obj.multiValueSelect; var modelEl = this.$('#' + obj.modalID);
obj.options = { modelEl.find(".attributeInput").css("borderColor", "transparent");;
"applicableEntityTypes": JSON.stringify(that.$el.find(".entityTypeSelector").val()), if (attrNames.indexOf(obj.name) > -1) {
"maxStrLength": that.$el.find(".stringLengthVal").val() ? that.$el.find(".stringLengthVal").val() : "0" that.highlightAttrinuteName(modelEl, obj);
}; isvalidName = false;
if (obj.typeName != "string" && obj.typeName != "boolean" && obj.typeName != "byte" && obj.typeName != "short" && obj.typeName != "int" && obj.typeName != "float" && obj.typeName != "double" && obj.typeName != "long" && obj.typeName != "date") { return true;
obj.typeName = obj.typeName; } else {
var enumName = enumDefCollection.fullCollection.findWhere({ name: obj.typeName }); attrNames.push(obj.name);
if (enumName) {
var enumDef = enumName.get('elementDefs');
if (enumDef.length === obj.enumValues.length) {
_.each(enumDef, function(enumVal, index) {
if (obj.enumValues.indexOf(enumVal.value) === -1) {
isPutCall = true;
};
})
} else {
isPutCall = true;
}
} else {
isPostCallEnum = true;
}
var elementValues = [];
_.each(obj.enumValues, function(inputEnumVal, index) {
elementValues.push({
"ordinal": index + 1,
"value": inputEnumVal
})
});
if (isPostCallEnum) {
enumDefs.push({
"name": obj.typeName,
"elementDefs": elementValues
})
}
if (isPutCall) {
putEnumDef.push({
"name": obj.typeName,
"elementDefs": elementValues
})
}
} }
if (isMultiCheck) { var elementValues = [];
obj.multiValued = true; that.namespaceAttributes(modelEl, obj, elementValues);
obj.typeName = "array<" + obj.typeName + ">"; if (that.isPostCallEnum) {
that.createEnumObject(enumDefs, obj, elementValues);
}
if (that.isPutCall) {
that.createEnumObject(putEnumDef, obj, elementValues);
} }
}); });
var notifyObj = { var notifyObj = {
...@@ -368,210 +389,178 @@ define(['require', ...@@ -368,210 +389,178 @@ define(['require',
} }
}; };
} }
this.json = { if (isvalidName) {
"enumDefs": enumDefs, this.json = {
"structDefs": [], "enumDefs": enumDefs,
"classificationDefs": [], "structDefs": [],
"entityDefs": [], "classificationDefs": [],
"namespaceDefs": [{ "entityDefs": [],
"category": "NAMESPACE", "namespaceDefs": [{
"createdBy": "admin", "category": "NAMESPACE",
"updatedBy": "admin", "createdBy": "admin",
"version": 1, "updatedBy": "admin",
"typeVersion": "1.1", "version": 1,
"name": name.trim(), "typeVersion": "1.1",
"description": description.trim(), "name": name.trim(),
"attributeDefs": attributeObj "description": description.trim(),
}] "attributeDefs": attributeObj
}; }]
};
var apiObj = { var apiObj = {
sort: false, sort: false,
success: function(model, response) { success: function(model, response) {
var nameSpaveDef = model.namespaceDefs; var nameSpaveDef = model.namespaceDefs;
if (nameSpaveDef) { if (nameSpaveDef) {
that.options.nameSpaceCollection.fullCollection.add(nameSpaveDef); that.options.nameSpaceCollection.fullCollection.add(nameSpaveDef);
Utils.notifySuccess({ Utils.notifySuccess({
content: "Namespace " + name + Messages.getAbbreviationMsg(false, 'addSuccessMessage') content: "Namespace " + name + Messages.getAbbreviationMsg(false, 'addSuccessMessage')
}); });
} }
that.checkLoader--; that.checkLoader--;
if (that.checkLoader == 0) { if (that.checkLoader == 0) {
that.options.onUpdateNamespace(); that.options.onUpdateNamespace();
}
},
silent: true,
reset: true,
complete: function(model, status) {
attrNames = [];
that.loaderStatus(false);
} }
},
silent: true,
reset: true,
complete: function(model, status) {
that.loaderStatus(false);
} }
}
that.checkLoader++;
$.extend(apiObj, { contentType: 'application/json', dataType: 'json', data: JSON.stringify(that.json) })
this.options.nameSpaceCollection.constructor.nonCrudOperation.call(this, UrlLinks.nameSpaceApiUrl(), "POST", apiObj);
if (isPutCall) {
var putData = {
"enumDefs": putEnumDef
};
that.checkLoader++; that.checkLoader++;
$.extend(apiObj, { contentType: 'application/json', dataType: 'json', data: JSON.stringify(putData) }) $.extend(apiObj, { contentType: 'application/json', dataType: 'json', data: JSON.stringify(that.json) })
this.options.nameSpaceCollection.constructor.nonCrudOperation.call(this, UrlLinks.typedefsUrl().defs, "PUT", apiObj); this.options.nameSpaceCollection.constructor.nonCrudOperation.call(this, UrlLinks.nameSpaceApiUrl(), "POST", apiObj);
if (that.isPutCall) {
var putData = {
"enumDefs": putEnumDef
};
that.checkLoader++;
$.extend(apiObj, { contentType: 'application/json', dataType: 'json', data: JSON.stringify(putData) })
this.options.nameSpaceCollection.constructor.nonCrudOperation.call(this, UrlLinks.typedefsUrl().defs, "PUT", apiObj);
}
} else {
attrNames = [];
} }
}, },
onUpdateAttr: function() { onUpdateAttr: function() {
var that = this, var that = this,
attrNameValidate = true, attrNameValidate = true,
enumValue = true, enumValue = true,
stringValidate = true, stringValidate = true,
attributeDefs = that.options.selectedNamespace.get('attributeDefs'),
enumDefs = [], enumDefs = [],
postEnumDef = [], postEnumDef = [],
isPutCall = false, selectedNamespace = $.extend(true, {}, that.options.selectedNamespace.toJSON()),
isPostCallEnum = false; attributeDefs = selectedNamespace['attributeDefs'],
isvalidName = true;
this.checkLoader = 0; this.checkLoader = 0;
this.isPutCall = false;
this.isPostCallEnum = false;
if (this.validateValues()) { if (this.validateValues()) {
return; return;
}; };
if (this.$el.find(".namespace-attr").length > 0 && this.collection.length > 0) { if (this.$el.find(".namespace-attr").length > 0 && this.collection.length > 0) {
this.loaderStatus(true); this.loaderStatus(true);
var attributeObj = this.collection.toJSON(), if (this.collection.length > 0) {
name = this.collection.first().get("name"), this.collection.each(function(model) {
multipleName = ''; var obj = model.toJSON(),
if (this.collection.length === 1 && this.collection.first().get("name") === "") { modelEl = this.$('#' + obj.modalID);
attributeObj = []; modelEl.find(".attributeInput").css("borderColor", "transparent");
} if (that.options.isNewAttr == true && _.find(attributeDefs, { name: obj.name })) {
if (attributeObj.length > 0) { that.highlightAttrinuteName(modelEl, obj);
_.each(attributeObj, function(obj) { isvalidName = false;
var isMultiCheck = obj.multiValueSelect; return true;
multipleName += obj.name + ", ";
obj.options = {
"applicableEntityTypes": JSON.stringify(that.$el.find(".entityTypeSelector").val()),
"maxStrLength": that.$el.find(".stringLengthVal").val() ? that.$el.find(".stringLengthVal").val() : "0"
};
if (obj.typeName != "string" && obj.typeName != "boolean" && obj.typeName != "byte" && obj.typeName != "short" && obj.typeName != "int" && obj.typeName != "float" && obj.typeName != "double" && obj.typeName != "long" && obj.typeName != "date") {
var enumName = enumDefCollection.fullCollection.findWhere({ name: obj.typeName });
if (enumName) {
var enumDef = enumName.get('elementDefs');
if (enumDef.length === obj.enumValues.length) {
_.each(enumDef, function(enumVal, index) {
if (obj.enumValues.indexOf(enumVal.value) === -1) {
isPutCall = true;
};
})
} else {
isPutCall = true;
}
} else {
isPostCallEnum = true;
}
var elementValues = [];
_.each(obj.enumValues, function(inputEnumVal, index) {
elementValues.push({
"ordinal": index + 1,
"value": inputEnumVal
})
});
if (isPostCallEnum) {
postEnumDef.push({
"name": obj.typeName,
"elementDefs": elementValues
})
} else if (isPutCall) {
enumDefs.push({
"name": obj.typeName,
"elementDefs": elementValues
})
}
} }
if (isMultiCheck) { var elementValues = [];
obj.multiValued = true; that.namespaceAttributes(modelEl, obj, elementValues);
obj.typeName = "array<" + obj.typeName + ">"; if (that.isPostCallEnum) {
that.createEnumObject(postEnumDef, obj, elementValues);
} else if (that.isPutCall) {
that.createEnumObject(enumDefs, obj, elementValues);
} }
}); if (that.options.isNewAttr == true) {
var notifyObj = { selectedNamespace.attributeDefs.push(obj);
modal: true, } else {
confirm: { var attrDef = selectedNamespace.attributeDefs;
confirm: true, _.each(attrDef, function(attrObj) {
buttons: [{ if (attrObj.name === that.$el.find(".attributeInput")[0].value) {
text: "Ok", attrObj.name = obj.name;
addClass: "btn-atlas btn-md", attrObj.typeName = obj.typeName;
click: function(notice) { attrObj.multiValued = obj.multiValueSelect || false;
notice.remove(); attrObj.options.applicableEntityTypes = obj.options.applicableEntityTypes;
} attrObj.enumValues = obj.enumValues;
}, attrObj.options.maxStrLength = obj.options.maxStrLength;
null
]
}
};
if (that.options.isNewAttr == true) {
_.each(attributeObj, function(obj) {
attributeDefs.push(obj);
})
} else {
var selectedNamespaceUpdateCopy = that.options.selectedNamespace;
var attrDef = selectedNamespaceUpdateCopy.toJSON().attributeDefs;
_.each(attrDef, function(attrObj) {
if (attrObj.name === that.$el.find(".attributeInput")[0].value) {
attrObj.name = attributeObj[0].name;
attrObj.typeName = attributeObj[0].typeName;
attrObj.multiValued = attributeObj[0].multiValueSelect || false;
attrObj.options.applicableEntityTypes = attributeObj[0].options.applicableEntityTypes;
attrObj.enumValues = attributeObj[0].enumValues;
attrObj.options.maxStrLength = attributeObj[0].options.maxStrLength;
}
});
}
var putNameSpace = function() {
that.checkLoader++;
$.extend(apiObj, { contentType: 'application/json', dataType: 'json', data: JSON.stringify(that.json) })
that.options.nameSpaceCollection.constructor.nonCrudOperation.call(that, UrlLinks.nameSpaceUpdateUrl(), "PUT", apiObj);
}
this.json = {
"enumDefs": enumDefs,
"structDefs": [],
"classificationDefs": [],
"entityDefs": [],
"namespaceDefs": that.options.isNewAttr ? [that.options.selectedNamespace.toJSON()] : [selectedNamespaceUpdateCopy.toJSON()]
};
var apiObj = {
sort: false,
success: function(model, response) {
if (model.namespaceDefs.length === 0 && model.enumDefs.length) {
putNameSpace();
} else {
var selectedNameSpace = that.options.nameSpaceCollection.fullCollection.findWhere({ guid: that.options.guid });
Utils.notifySuccess({
content: "One or more Namespace attribute" + Messages.getAbbreviationMsg(false, 'editSuccessMessage')
});
if (model.namespaceDefs && model.namespaceDefs.length) {
that.options.selectedNamespace.set(model.namespaceDefs[0]);
} }
that.options.onEditCallback(); });
} }
that.checkLoader--; });
if (that.checkLoader == 0) { if (isvalidName) {
that.options.onUpdateNamespace(); var notifyObj = {
modal: true,
confirm: {
confirm: true,
buttons: [{
text: "Ok",
addClass: "btn-atlas btn-md",
click: function(notice) {
notice.remove();
}
},
null
]
} }
};
}, var putNameSpace = function() {
silent: true, that.checkLoader++;
reset: true, $.extend(apiObj, { contentType: 'application/json', dataType: 'json', data: JSON.stringify(that.json) })
complete: function(model, status) { that.options.nameSpaceCollection.constructor.nonCrudOperation.call(that, UrlLinks.nameSpaceUpdateUrl(), "PUT", apiObj);
that.loaderStatus(false);
} }
} this.json = {
if (isPostCallEnum) { "enumDefs": enumDefs,
var postData = { "structDefs": [],
"enumDefs": postEnumDef "classificationDefs": [],
"entityDefs": [],
"namespaceDefs": that.options.isNewAttr ? [selectedNamespace] : [selectedNamespace]
}; };
this.checkLoader++; var apiObj = {
$.extend(apiObj, { contentType: 'application/json', dataType: 'json', data: JSON.stringify(postData) }) sort: false,
this.options.nameSpaceCollection.constructor.nonCrudOperation.call(this, UrlLinks.typedefsUrl().defs, "POST", apiObj); success: function(model, response) {
} else { if (model.namespaceDefs.length === 0 && model.enumDefs.length) {
putNameSpace(); putNameSpace();
} else {
var selectedNameSpace = that.options.nameSpaceCollection.fullCollection.findWhere({ guid: that.options.guid });
Utils.notifySuccess({
content: "One or more Namespace attribute" + Messages.getAbbreviationMsg(false, 'editSuccessMessage')
});
if (model.namespaceDefs && model.namespaceDefs.length) {
that.options.selectedNamespace.set(model.namespaceDefs[0]);
}
that.options.onEditCallback();
}
that.checkLoader--;
if (that.checkLoader == 0) {
that.options.onUpdateNamespace();
}
},
silent: true,
reset: true,
complete: function(model, status) {
that.loaderStatus(false);
}
}
if (that.isPostCallEnum) {
var postData = {
"enumDefs": postEnumDef
};
this.checkLoader++;
$.extend(apiObj, { contentType: 'application/json', dataType: 'json', data: JSON.stringify(postData) })
this.options.nameSpaceCollection.constructor.nonCrudOperation.call(this, UrlLinks.typedefsUrl().defs, "POST", apiObj);
} else {
putNameSpace();
}
} }
} }
} else { } else {
......
...@@ -89,12 +89,20 @@ define(["require", "backbone", "hbs!tmpl/name_space/EnumCreateUpdateItemView_tmp ...@@ -89,12 +89,20 @@ define(["require", "backbone", "hbs!tmpl/name_space/EnumCreateUpdateItemView_tmp
entitytypes = "", entitytypes = "",
enumTypes = []; enumTypes = [];
this.ui.enumValueSelectorContainer.hide(); this.ui.enumValueSelectorContainer.hide();
this.bindEvents();
this.emumTypeSelectDisplay(); this.emumTypeSelectDisplay();
if (!this.options.closeModal) { if (!this.options.closeModal) {
this.ui.enumCancleBtn.attr("disabled", "true"); this.ui.enumCancleBtn.attr("disabled", "true");
this.ui.enumCancleBtn.text("Clear"); this.ui.enumCancleBtn.text("Clear");
} }
}, },
bindEvents: function() {
var that = this;
this.listenTo(this.enumDefCollection, 'reset', function() {
that.emumTypeSelectDisplay();
})
},
showEnumValues: function(enumName) { showEnumValues: function(enumName) {
var enumValues = "", var enumValues = "",
selectedValues = [], selectedValues = [],
...@@ -225,7 +233,8 @@ define(["require", "backbone", "hbs!tmpl/name_space/EnumCreateUpdateItemView_tmp ...@@ -225,7 +233,8 @@ define(["require", "backbone", "hbs!tmpl/name_space/EnumCreateUpdateItemView_tmp
content: "Enumeration " + selectedEnumName + " updated successfully" content: "Enumeration " + selectedEnumName + " updated successfully"
}); });
} }
if (that.options.onUpdateEnum) { that.enumDefCollection.fetch({ reset: true });
if (that.options.onUpdateEnum) { //callback from namespaceattributeItemView
that.options.onUpdateEnum(); that.options.onUpdateEnum();
} }
that.ui.enumCancleBtn.attr("disabled", "true"); that.ui.enumCancleBtn.attr("disabled", "true");
......
...@@ -30,6 +30,11 @@ define(['require', ...@@ -30,6 +30,11 @@ define(['require',
{ {
template: NameSpaceAttributeItemViewTmpl, template: NameSpaceAttributeItemViewTmpl,
templateHelpers: function() {
return {
modalID: this.viewId
};
},
/** Layout sub regions */ /** Layout sub regions */
regions: {}, regions: {},
...@@ -109,12 +114,14 @@ define(['require', ...@@ -109,12 +114,14 @@ define(['require',
*/ */
initialize: function(options) { initialize: function(options) {
this.parentView = options.parentView; this.parentView = options.parentView;
this.viewId = options.model ? options.model.cid : this.parentView.cid;
}, },
onRender: function() { onRender: function() {
var that = this, var that = this,
entitytypes = '', entitytypes = '',
enumTypes = []; enumTypes = [];
this.model.set({ "modalID": this.viewId });
this.parentView.typeHeaders.fullCollection.each(function(model) { this.parentView.typeHeaders.fullCollection.each(function(model) {
if (model.toJSON().category == "ENTITY") { if (model.toJSON().category == "ENTITY") {
that.ui.entityTypeSelector.append("<option>" + model.get('name') + "</option>"); that.ui.entityTypeSelector.append("<option>" + model.get('name') + "</option>");
......
...@@ -151,15 +151,15 @@ define(['require', ...@@ -151,15 +151,15 @@ define(['require',
}, },
onEditAttr: function(e) { onEditAttr: function(e) {
var that = this, var that = this,
isAttrEdit = e.target.dataset && e.target.dataset.id === 'attributeEdit' ? true : false, isAttrEdit = e.currentTarget.dataset && e.currentTarget.dataset.id === 'attributeEdit' ? true : false,
guid = e.target.dataset && e.target.dataset.guid ? e.target.dataset.guid : null, guid = e.currentTarget.dataset && e.currentTarget.dataset.guid ? e.currentTarget.dataset.guid : null,
selectedNamespace = that.nameSpaceCollection.fullCollection.findWhere({ guid: guid }), selectedNamespace = that.nameSpaceCollection.fullCollection.findWhere({ guid: guid }),
attrributes = selectedNamespace ? selectedNamespace.get('attributeDefs') : null, attrributes = selectedNamespace ? selectedNamespace.get('attributeDefs') : null,
attrName = e.target.dataset.name ? e.target.dataset.name : null, attrName = e.currentTarget.dataset.name ? e.currentTarget.dataset.name : null,
attrDetails = { name: attrName }; attrDetails = { name: attrName };
if (selectedNamespace) { if (selectedNamespace) {
that.ui.namespaceAttrPageOk.text("Save"); that.ui.namespaceAttrPageOk.text("Save");
that.newAttr = e.target && e.target.dataset.action === "createAttr" ? true : false; that.newAttr = e.currentTarget && e.currentTarget.dataset.action === "createAttr" ? true : false;
that.guid = guid; that.guid = guid;
_.each(attrributes, function(attrObj) { _.each(attrributes, function(attrObj) {
if (attrObj.name === attrName) { if (attrObj.name === attrName) {
...@@ -176,7 +176,7 @@ define(['require', ...@@ -176,7 +176,7 @@ define(['require',
that.showDetails = false; that.showDetails = false;
that.toggleNamespaceDetailsAttrView(); that.toggleNamespaceDetailsAttrView();
that.ui.namespaceAttrPageOk.attr('data-action', e.target.dataset.id); that.ui.namespaceAttrPageOk.attr('data-action', e.currentTarget.dataset.id);
require(["views/name_space/CreateNameSpaceLayoutView"], function(CreateNameSpaceLayoutView) { require(["views/name_space/CreateNameSpaceLayoutView"], function(CreateNameSpaceLayoutView) {
that.view = new CreateNameSpaceLayoutView({ that.view = new CreateNameSpaceLayoutView({
onEditCallback: function() { onEditCallback: function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment