<commit_before>/*
 * The contents of this file are subject to the OpenMRS Public License
 * Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */
define(
	[
			openhmis.url.backboneBase + 'js/model/generic',
			openhmis.url.backboneBase + 'js/lib/i18n',
			openhmis.url.backboneBase + 'js/model/fieldGenHandler'
	],
	function(openhmis, __) {
		openhmis.AttributeTypeBase = openhmis.GenericModel.extend({
			meta: {},
			schema: {},

			initialize: function (attributes, options) {
				openhmis.GenericModel.prototype.initialize.call(this, attributes, options);

				// All instance attribute types are metadata
				this.meta.openmrsType = "metadata";

				// Add default names if not defined
				if (this.meta === undefined || this.meta.name === undefined) {
					this.meta.name = "Attribute Type";
				}
				if (this.meta === undefined || this.meta.namePlural === undefined) {
					this.meta.namePlural = "Attribute Types";
				}

				// Add default schema fields
				this.schema.name = { type: 'Text' };
				this.schema.format = {
					type: 'Select',
					options: new openhmis.FieldFormatCollection()
				};
				this.schema.foreignKey = { type: 'BasicNumber' };
				this.schema.regExp = { type: 'Text' };
				this.schema.required = { type: 'Checkbox' };
                this.schema.attributeOrder = {type: 'Hidden'};
			},

			validate: function (attrs, options) {
				if (!attrs.name) {
					return { name: __("A name is required") }
				}
				return null;
			},

			toString: function () {
				return this.get('name');
			}
		});

        openhmis.AttributeBase = openhmis.GenericModel.extend({
            schema: {},

            attributeTypeClass: null,
            attributeTypeEditor: null,

            initialize: function(attributes, options) {
                openhmis.GenericModel.prototype.initialize.call(this, attributes, options);

                var temp = new this.attributeTypeClass();

                this.schema.attributeType = {
                    type: this.attributeTypeEditor,
                    title: temp.meta.name,
                    options: new openhmis.GenericCollection(null, {
                        model: this.attributeTypeClass,
                        url: temp.meta.restUrl
                    }),
                    objRef: true
                };
                this.schema.value = {
                    type: "Text"
                };
            },

            parse: function(resp) {
                if (resp.attributeType) {
                    resp.attributeType = new this.attributeTypeClass(resp.attributeType, { parse: true });
                }

                return resp;
            }
        });

		openhmis.CustomizableInstanceTypeBase = openhmis.GenericModel.extend({<commit_msg>Updated attribute order to be enterable by default.<commit_after>/*
 * The contents of this file are subject to the OpenMRS Public License
 * Version 2.0 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://license.openmrs.org
 *
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
 * License for the specific language governing rights and limitations
 * under the License.
 *
 * Copyright (C) OpenMRS, LLC.  All Rights Reserved.
 */
define(
	[
			openhmis.url.backboneBase + 'js/model/generic',
			openhmis.url.backboneBase + 'js/lib/i18n',
			openhmis.url.backboneBase + 'js/model/fieldGenHandler'
	],
	function(openhmis, __) {
		openhmis.AttributeTypeBase = openhmis.GenericModel.extend({
			meta: {},
			schema: {},

			initialize: function(attributes, options) {
				openhmis.GenericModel.prototype.initialize.call(this, attributes, options);

				// All instance attribute types are metadata
				this.meta.openmrsType = "metadata";

				// Add default names if not defined
				if (this.meta === undefined || this.meta.name === undefined) {
					this.meta.name = "Attribute Type";
				}
				if (this.meta === undefined || this.meta.namePlural === undefined) {
					this.meta.namePlural = "Attribute Types";
				}

				// Add default schema fields
				this.schema.name = { type: 'Text' };
				this.schema.format = {
					type: 'Select',
					options: new openhmis.FieldFormatCollection()
				};
				this.schema.foreignKey = { type: 'BasicNumber' };
				this.schema.regExp = { type: 'Text' };
				this.schema.required = { type: 'Checkbox' };
                this.schema.attributeOrder = {type: 'BasicNumber'};
			},

			validate: function(attrs, options) {
				if (!attrs.name) {
					return { name: __("A name is required") }
				}
				return null;
			},

			toString: function() {
				return this.get('name');
			}
		});

        openhmis.InstanceAttributeTypeBase = openhmis.AttributeTypeBase.extend({
            initialize: function (attributes, options) {
                openhmis.AttributeTypeBase.prototype.initialize.call(this, attributes, options);

                this.schema.attributeOrder = {type: 'Hidden'};
            }
        });

        openhmis.AttributeBase = openhmis.GenericModel.extend({
            schema: {},

            attributeTypeClass: null,
            attributeTypeEditor: null,

            initialize: function(attributes, options) {
                openhmis.GenericModel.prototype.initialize.call(this, attributes, options);

                var temp = new this.attributeTypeClass();

                this.schema.attributeType = {
                    type: this.attributeTypeEditor,
                    title: temp.meta.name,
                    options: new openhmis.GenericCollection(null, {
                        model: this.attributeTypeClass,
                        url: temp.meta.restUrl
                    }),
                    objRef: true
                };
                this.schema.value = {
                    type: "Text"
                };
            },

            parse: function(resp) {
                if (resp.attributeType) {
                    resp.attributeType = new this.attributeTypeClass(resp.attributeType, { parse: true });
                }

                return resp;
            },

            toString: function() {
                return this.get('attributeType').name + ': ' + this.get('value');
            }
        });

		openhmis.CustomizableInstanceTypeBase = openhmis.GenericModel.extend({
{'fraction_non_alphanumeric': 0.11176212099018602, 'fraction_numerical': 0.001171817782334847, 'mean_word_length': 2.1163852122318576, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '524641', 'n_tokens_mistral': 2076, 'n_tokens_neox': 1792, 'n_words': 461}