in dashboardv3/public/js/views/glossary/AssignTermLayoutView.js [153:276]
assignTerm: function() {
this.assignTermError = false;
var that = this,
data = [],
termAttributeFormData = [],
selectedItem = this.glossary.selectedItem,
selectedGuid = selectedItem.guid,
termName = selectedItem.text,
ajaxOptions = {
success: function(rModel, response) {
Utils.notifySuccess({
content: (that.isCategoryView || that.isEntityView || that.isAttributeRelationView ? "Term" : "Category") + " is associated successfully "
});
if (that.callback) {
that.callback();
}
},
cust_error: function() {
var $assignBtn = that.$el.find('a[href="#finish"]');
$assignBtn.removeAttr('disabled').hideButtonLoader();
$assignBtn.parent().attr('aria-disabled', 'false').removeClass('disabled');
that.assignTermError = true;
},
complete: function() {
that.modal.trigger('closeModal');
}
},
model = new this.glossaryCollection.model();
if (this.isCategoryView) {
data = $.extend(true, {}, this.categoryData);
if (data.terms) {
data.terms.push({ "termGuid": selectedGuid });
} else {
data.terms = [{ "termGuid": selectedGuid }];
}
model.assignTermToCategory(_.extend(ajaxOptions, { data: JSON.stringify(data), guid: data.guid }));
} else if (this.isTermView) {
data = $.extend(true, {}, this.termData);
if (data.categories) {
data.categories.push({ "categoryGuid": selectedGuid });
} else {
data.categories = [{ "categoryGuid": selectedGuid }];
}
model.assignCategoryToTerm(_.extend(ajaxOptions, { data: JSON.stringify(data), guid: data.guid }));
} else if (this.isAttributeRelationView) {
termAttributeFormData = this.$('[data-id="termAttributeForm"]').serializeArray().reduce(function(obj, item) {
obj[item.name] = item.value;
return obj;
}, {}),
data = $.extend(true, {}, this.termData);
if (data[this.selectedTermAttribute]) {
data[this.selectedTermAttribute].push(_.extend({ "termGuid": selectedGuid }, termAttributeFormData));
} else {
data[this.selectedTermAttribute] = [_.extend({ "termGuid": selectedGuid }, termAttributeFormData)];
}
model.assignTermToAttributes(_.extend(ajaxOptions, { data: JSON.stringify(data), guid: data.guid }));
} else {
var deletedEntity = [],
skipEntity = [];
if (this.multiple) {
_.each(that.multiple, function(entity, i) {
var name = Utils.getName(entity.model);
if (Enums.entityStateReadOnly[entity.model.status]) {
deletedEntity.push(name);
} else {
if (_.indexOf((entity.model.meaningNames || _.pluck(entity.model.meanings, 'displayText')), termName) === -1) {
data.push({ guid: entity.model.guid })
} else {
skipEntity.push(name);
}
}
});
if (deletedEntity.length) {
Utils.notifyError({
html: true,
content: "<b>" + deletedEntity.join(', ') +
"</b> " + (deletedEntity.length === 1 ? "entity " : "entities ") +
Messages.assignTermDeletedEntity
});
that.modal.close();
}
} else {
data.push({ "guid": that.guid });
}
if (skipEntity.length) {
var text = "<b>" + skipEntity.length + " of " + that.multiple.length +
"</b> entities selected have already been associated with <b>" + termName +
"</b> term, Do you want to associate the term with other entities ?",
removeCancelButton = false;
if ((skipEntity.length + deletedEntity.length) === that.multiple.length) {
text = (skipEntity.length > 1 ? "All selected" : "Selected") + " entities have already been associated with <b>" + termName + "</b> term";
removeCancelButton = true;
}
var notifyObj = {
text: text,
modal: true,
ok: function(argument) {
if (data.length) {
model.assignTermToEntity(selectedGuid, _.extend(ajaxOptions, { data: JSON.stringify(data) }));
}
},
cancel: function(argument) {}
}
if (removeCancelButton) {
notifyObj['confirm'] = {
confirm: true,
buttons: [{
text: 'Ok',
addClass: 'btn-atlas btn-md',
click: function(notice) {
notice.remove();
}
},
null
]
}
}
Utils.notifyConfirm(notifyObj);
} else if (data.length) {
model.assignTermToEntity(selectedGuid, _.extend(ajaxOptions, { data: JSON.stringify(data) }));
}
}
},