function PrototypeItem(prototype_manager) { this.on_remove = null; this.content_container = null; this.on_generate_indexed_element_id = null; this.prototype_manager = prototype_manager; this.add_button = prototype_manager.add_button; this.remove_button = prototype_manager.remove_button; this.parent_container = prototype_manager.parent_container; this.html_prototype = (prototype_manager.useActualVersion) ? $(prototype_manager.html_prototype).outerHTML() : prototype_manager.html_prototype; this._index = PrototypeItem.nocs_index_counter + 1; PrototypeItem.nocs_index_counter++; this.InitializeControls(); } PrototypeItem.prototype.UpdateContainerAttribute = function(container, attribute_name) { var object = this; var container_property = container.getAttribute(attribute_name); if (container_property) { container_property = object.GetIndexedElementID(container_property); container.setAttribute(attribute_name, container_property); } $(container).children().each(function (index, child) { object.UpdateContainerAttribute(child, attribute_name); }); } PrototypeItem.prototype.UpdateContainerID = function(container) { var object = this; if (container.id) { container.id = object.GetIndexedElementID(container.id); } $(container).children().each(function (index, child) { object.UpdateContainerID(child); }); } PrototypeItem.prototype.UpdateContainerProperties = function(container) { this.UpdateContainerID(container); this.UpdateContainerAttribute(container, 'for'); } PrototypeItem.prototype.CloneContainer = function () { if ((this.content_container == null) && (this.html_prototype != "")) { var object = this; this.content_container = $.parseHTML(this.html_prototype)[0]; $(this.content_container).removeClass("prototype"); this.UpdateContainerProperties(this.content_container); $(this.content_container).find(".prototype-item-skip").remove(); this.jquery = $(this.parent_container)[0].appendChild(this.content_container); if (this.remove_button) { $(this.GetIndexedElementID(this.remove_button))[0].onclick = function(event) { object.Remove(); event.stopPropagation() }; } if (this.add_button) { $(this.GetIndexedElementID(this.add_button))[0].onclick = function() { object.prototype_manager.AddItem(); }; } } } PrototypeItem.prototype.InitializeControls = function () { this.CloneContainer(); } PrototypeItem.prototype.OnRemove = function (event) { this.on_remove = event; } PrototypeItem.prototype.GetInputChecked = function(element_id) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id); return $(element_id).prop("checked"); } return false; } PrototypeItem.prototype.SetInputChecked = function(element_id, is_checked) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id); $(element_id).prop("checked", is_checked); } } PrototypeItem.prototype.GetInputValue = function (element_id) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id); return $(element_id).val(); } return ""; } PrototypeItem.prototype.SetInputValue = function (element_id, value) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id); $(element_id).val(value); } } PrototypeItem.prototype.GetSelectValue = function (element_id) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id) + " option:selected"; return $(element_id).val(); } return ""; } PrototypeItem.prototype.SetSelectValue = function (element_id, value) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id); $(element_id + " option[value='" + value + "']").attr('selected', true); $(element_id).change(); } } PrototypeItem.prototype.GetHTMLValue = function (element_id) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id); return $(element_id).html(); } return ""; } PrototypeItem.prototype.SetHTMLValue = function (element_id, value) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id); $(element_id).html(value); } } PrototypeItem.prototype.SetFocus = function (element_id) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id); $(element_id).focus(); } } PrototypeItem.prototype.GetAttributeValue = function (element_id, attribute_name) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id); return $(element_id).attr(attribute_name); } return ""; } PrototypeItem.prototype.SetAttributeValue = function (element_id, attribute_name, attribute_value) { if (element_id) { element_id = "#" + this.GetIndexedElementID(element_id); $(element_id).attr(attribute_name, attribute_value); } } PrototypeItem.prototype.GetIndexedElementID = function (element_id) { var result = ""; if (element_id) { if (this.prototype_manager.on_generate_indexed_element_id) result = this.prototype_manager.on_generate_indexed_element_id(element_id, this._index); if (!Assigned(result)) result = element_id + this._index; } return result; } PrototypeItem.prototype.Remove = function () { if (this.content_container != null) { $(this.content_container).remove(); if (this.on_remove) this.on_remove(this); } } PrototypeItem.nocs_index_counter = 0;