define("UsrClass1Page", [], function() {
return {
entitySchemaName: "UsrClass",
messages: {},
attributes: {
/* The attribute that stores the number of currently active daily classes. */
"responseCollectionTrainings": {
"dataValueType": Terrasoft.DataValueType.INTEGER,
"type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN
},
/* The attribute that stores the value of the system setting. */
"maximumDailyActiveSections": {
"dataValueType": Terrasoft.DataValueType.INTEGER,
"type": Terrasoft.ViewModelColumnType.VIRTUAL_COLUMN
}
},
methods: {
/* Run when the page's schema is loaded and call the method that counts the current number of active daily classes and the method that reads the value of the system setting. */
onEntityInitialized: function(){
this.callParent(arguments);
this.getPeriodicityActiveNumber();
this.getMaximumDailyActiveSections();
},
/* Calculate the current number of active daily classes and write the calculated value to the "responseCollectionTrainings" attribute. */
getPeriodicityActiveNumber: function() {
var periodicity = "Daily";
var esqPeriodicity = this.Ext.create("Terrasoft.EntitySchemaQuery", {
rootSchemaName: "UsrClass"
});
esqPeriodicity.addColumn("UsrName");
var groupFilters = this.Ext.create("Terrasoft.FilterGroup");
var filterPerodicity = this.Terrasoft.createColumnFilterWithParameter(this.Terrasoft.ComparisonType.EQUAL, "UsrPeriodicity.Name", periodicity);
var thisId = this.get("Id");
var filterId = this.Terrasoft.createColumnFilterWithParameter(this.Terrasoft.ComparisonType.NOT_EQUAL, "Id", thisId);
var filterIsActive = this.Terrasoft.createColumnFilterWithParameter(this.Terrasoft.ComparisonType.EQUAL, "UsrIsActive", true);
groupFilters.addItem(filterPerodicity);
groupFilters.logicalOperation = this.Terrasoft.LogicalOperatorType.AND;
groupFilters.addItem(filterIsActive);
groupFilters.logicalOperation = this.Terrasoft.LogicalOperatorType.AND;
groupFilters.addItem(filterId);
esqPeriodicity.filters.add(groupFilters);
esqPeriodicity.getEntityCollection(function(result) {
if (!result.success) {
this.showInformationDialog("Request error");
return;
}
else {
var lengthCollection = result.collection.collection.length;
this.set("responseCollectionTrainings", lengthCollection);
}
}, this);
},
/* Provide validation for the "Periodicity" field. The validator method will be called each time the field is modified or the record is saved. */
setValidationConfig: function() {
this.callParent(arguments);
this.addColumnValidator("UsrPeriodicity", this.periodicityValidator);
},
/* The validator method: if the class is daily, compare the number of active daily classes to the "GymNumber" system setting. Add a warning message to the "Periodicity" field if the system setting's value is exceeded. Saving the record is impossible in this case. */
periodicityValidator: function() {
var invalidMessage= "";
var periodicity = this.get("UsrPeriodicity").displayValue;
if (periodicity==="Daily") {
var isActive = this.get("UsrIsActive");
var myVariable = this.get("maximumDailyActiveSections");
var lengthCollection = this.get("responseCollectionTrainings");
if (lengthCollection >= myVariable && isActive) {
invalidMessage = "The number of gyms is limited. No more than " + myVariable + " daily trainings.";
}
}
else {
invalidMessage = "";
}
return {
invalidMessage: invalidMessage
};
},
/* Retrieve the value of the "GymNumber" system setting. */
getMaximumDailyActiveSections: function() {
var myVariable;
var callback = function(value) {
myVariable = value;
};
this.Terrasoft.SysSettings.querySysSettingsItem("GymsNumber", callback, this);
if (myVariable === undefined) {
return;
}
else {
this.set("maximumDailyActiveSections", myVariable);
}
}
},
modules: /**SCHEMA_MODULES*/{}/**SCHEMA_MODULES*/,
/* No changes. */
details: /**SCHEMA_DETAILS*/{
// …
}/**SCHEMA_DETAILS*/,
businessRules: /**SCHEMA_BUSINESS_RULES*/{}/**SCHEMA_BUSINESS_RULES*/,
dataModels: /**SCHEMA_DATA_MODELS*/{}/**SCHEMA_DATA_MODELS*/,
/* No changes. */
diff: /**SCHEMA_DIFF*/[
// …
]/**SCHEMA_DIFF*/
};
});