define([ "config", "constants", "storage_utils", "jquery", "underscore", "backbone", ], function(config, constants, storage_utils){ /** * Model for submit assistant. Store all configuration data */ var SubmitAssistantModel = Backbone.Model.extend({ defaults: { //type of SA "type_SA": undefined, "API_version": undefined, //configuration parameters "is_locked": undefined, "administration_group": undefined, "is_admin": false, "is_validation_branch": false, "validation_branches": undefined, }, /** * See Backbone documentation. * * @param type_SA - the type of the SA. * @param API_version - the version of the API. * @param is_locked - boolean indicating if validation process is enable. * @param administration_group - the name of the perforce administration group, * not affecting by validation process. */ initialize: function(){ }, /** * Check if SA is in validation process mode. * Check if user is admin. * If not, check if one of the file of the CL is on validation branch. * * @param changelistModel - the model of the changelist. */ checkValidationProcess: function(changelistModel){ if(this.get("is_locked")){ //1st: check if admin var groups = storage_utils.getGroups(); var i = 0; var length = groups.length; while(i < length && ! this.get("is_admin")){ if(groups[i] == this.get("administration_group")){ this.set("is_admin", true); } i++; } if(! this.get("is_admin")){ //2nd: if not admin, check if at least one file belongs to one of the validation branches var validation_branches = ""; var stringified_changelist = JSON.stringify(changelistModel.toJSON()); if(this.get("type_SA") === constants.type_code){ var i = 0; var length = config.code_branch.length; while(! this.get("is_validation_branch") && i < length){ var regex = new RegExp("\"Files[0-9]+\":\"" + config.code_branch[i]); this.set("is_validation_branch", stringified_changelist.match(regex) ? true : false); i++; } this.set("validation_branches", config.code_branch); } else if(this.get("type_SA") === constants.type_data){ var i = 0; var length = config.data_branch.length; while(! this.get("is_validation_branch") && i < length){ var regex = new RegExp("\"Files[0-9]+\":\"" + config.data_branch[i]); this.set("is_validation_branch", stringified_changelist.match(regex) ? true : false); i++; } this.set("validation_branches", config.data_branch); } } } }, }); return SubmitAssistantModel; });