in dashboardv2/public/js/views/tag/addTagModalView.js [55:183]
initialize: function(options) {
_.extend(this, _.pick(options, 'modalCollection', 'guid', 'callback', 'multiple', 'showLoader', 'hideLoader', 'tagList', 'tagModel', 'enumDefCollection'));
this.collection = new VTagList();
this.commonCollection = new VTagList();
var that = this,
modalObj = {
title: 'Add Tag',
content: this,
okText: 'Add',
cancelText: "Cancel",
allowCancel: true,
};
if (this.tagModel) {
modalObj.title = 'Edit Tag';
modalObj.okText = 'Update';
}
this.modal = new Modal(modalObj).open();
this.modal.$el.find('button.ok').attr("disabled", true);
this.on('ok', function() {
var tagName = this.tagModel ? this.tagModel.typeName : this.ui.addTagOptions.val(),
tagAttributes = {},
tagAttributeNames = this.$(".attrName"),
obj = {
tagName: tagName,
tagAttributes: tagAttributes,
guid: [],
skipEntity: [],
deletedEntity: []
};
tagAttributeNames.each(function(i, item) {
var selection = $(item).data("key");
var datatypeSelection = $(item).data("type");
if (datatypeSelection === "date") {
tagAttributes[selection] = Date.parse($(item).val()) || null;
} else {
tagAttributes[selection] = $(item).val() || null;
}
});
if (that.multiple) {
_.each(that.multiple, function(entity, i) {
var name = Utils.getName(entity.model);
if (Enums.entityStateReadOnly[entity.model.status]) {
obj.deletedEntity.push(name);
} else {
if (_.indexOf((entity.model.classificationNames || _.pluck(entity.model.classifications, 'typeName')), tagName) === -1) {
obj.guid.push(entity.model.guid)
} else {
obj.skipEntity.push(name);
}
}
});
if (obj.deletedEntity.length) {
Utils.notifyError({
html: true,
content: "<b>" + obj.deletedEntity.join(', ') +
"</b> " + (obj.deletedEntity.length === 1 ? "entity " : "entities ") +
Messages.assignDeletedEntity
});
}
if (obj.skipEntity.length) {
var text = "<b>" + obj.skipEntity.length + " of " + that.multiple.length +
"</b> entities selected have already been associated with <b>" + tagName +
"</b> tag, Do you want to associate the tag with other entities ?",
removeCancelButton = false;
if ((obj.skipEntity.length + obj.deletedEntity.length) === that.multiple.length) {
text = (obj.skipEntity.length > 1 ? "All selected" : "Selected") + " entities have already been associated with <b>" + tagName + "</b> tag";
removeCancelButton = true;
}
var notifyObj = {
text: text,
modal: true,
ok: function(argument) {
if (obj.guid.length) {
that.saveTagData(obj);
} else {
that.hideLoader();
}
},
cancel: function(argument) {
that.hideLoader();
obj = {
tagName: tagName,
tagAttributes: tagAttributes,
guid: [],
skipEntity: [],
deletedEntity: []
}
}
}
if (removeCancelButton) {
notifyObj['confirm'] = {
confirm: true,
buttons: [{
text: 'Ok',
addClass: 'btn-primary',
click: function(notice) {
notice.remove();
obj = {
tagName: tagName,
tagAttributes: tagAttributes,
guid: [],
skipEntity: [],
deletedEntity: []
}
}
},
null
]
}
}
Utils.notifyConfirm(notifyObj)
} else {
if (obj.guid.length) {
that.saveTagData(obj);
} else {
that.hideLoader();
}
}
} else {
obj.guid.push(that.guid);
that.saveTagData(obj);
}
});
this.on('closeModal', function() {
this.modal.trigger('cancel');
});
this.bindEvents();
},