Managers.GroupManager = Backbone.Model.extend({ id: null, edmanager: null, /* take a View instance as parameter (used by cascading Template) * Do not use manually * */ views: function(o) { if (!o) return this._views; else this._views=o; }, options: function(sOption, sValue) { if (!sOption) { return this._options; } else { this._options.set(sOption, sValue); this._optionsApplied = false; } }, initialize: function() {//sID, options) { //this.id = sID; this.id = this.get("id"); this.edmanager = window.edeal.edmanager; this.options.ismouseover = false; this.options.isfocused = false; this.options.haschanged = false; if (!this.options.requiredfieldpolicy) { this.options.requiredfieldpolicy = "FIELD_POLICY"; } if (!this.options.isreadonly) { this.options.isreadonly = false; } this._views = new Backbone.Collection(); if (!this.edmanager.groups.get(this.id)) { this.edmanager.groups.add({id: this.id, group:this}); } }, setPropertiesForView: function(view) { if (this.options.requireddisplaypolicy == "ALL_REQUIRED") { view.isRequired(true); view.options.ispartialrequired = false; } else { if (this.options.requireddisplaypolicy == "AT_LEAST_ONE_REQUIRED") { view.isRequired(false); view.options.ispartialrequired = true; } else { view.options.ispartialrequired = false; view.isRequired(view.options.initialisrequired); } } if (this.options.isreadonly == true) { view.isReadOnly(true); } else { view.isReadOnly(view.options.initialisreadonly); } }, applyOptions: function() { if (!this.options.optionsapplied) { var that = this; this._views.each(function(viewItem) { that.setPropertiesForView(viewItem.get("view")); }); this.options.optionsapplied = true; } }, change: function(fromView) { this.options.haschanged = true; if (this._views) { this._views.each(function(viewItem) { viewItem.get("view").setCSS(); }); } }, isAllViewsEmpty: function() { var allViewsEmpty = true; this._views.each(function(viewItem) { if (allViewsEmpty) { if (viewItem.get("view").classType != "VIEWS.LABEL") { if (!viewItem.get("view").model.isEmpty()) { allViewsEmpty = false; } } } }); return allViewsEmpty; }, isOneViewNotEmpty: function() { var oneViewNotEmpty = false; this._views.each(function(viewItem) { if (!oneViewNotEmpty) { if (viewItem.get("view").classType != "VIEWS.LABEL") { if (viewItem.get("view").model.getValue() != "") { oneViewNotEmpty = true; } } } }); return oneViewNotEmpty; }, setAllViewOnError: function() { this._views.each(function(viewItem) { viewItem.get("view").options.isonerror = true; viewItem.get("view").setCSS(); }); }, setAllViewNotOnError: function() { this._views.each(function(viewItem) { viewItem.get("view").options.isonerror = false; viewItem.get("view").setCSS(); }); }, mouseover: function(fromView) { this.options.ismouseover = true; var parentView = fromView.options.parentview; if (parentView) { if (!parentView.options.ismouseover) { // parentView._isMouseOver = true; // parentView.setCSS(); } } this._views.each(function(viewItem) { var aView = viewItem.get("view"); viewItem.get("view").options.ismouseover = true; viewItem.get("view").setCSS(); }); }, mouseout: function(fromView) { if (this.options.isfocused == false) { var mustContinue = true; var parentView = fromView.options.parentview; if (parentView) { /*console.log("parentView = " + parentView.id); console.log("parentView mouseover ? " + parentView._isMouseOver);*/ if (parentView.options.ismouseover == true) { mustContinue = false; fromView.options.ismouseover = true; } } if (mustContinue) { this.options.ismouseover = false; this._views.each(function(viewItem) { var aView = viewItem.get("view"); aView.options.ismouseover = false; aView.setCSS(); }); } } }, focus: function(fromView) { this.options.isfocused = true; this._views.each(function(viewItem) { if (viewItem.get("view") == fromView) { viewItem.get("view").setCSS(); } else { viewItem.get("view").options.ismouseover = true; viewItem.get("view").setCSS(); } }); }, blur: function(fromView) { this.options.isfocused = false; this._views.each(function(viewItem) { viewItem.get("view").options.isfocused = false; viewItem.get("view").options.ismouseover = false; viewItem.get("view").setCSS(); }); }, getJSON: function() { return "{id: " + this.id + ", value: " + this.getValue() + "}"; } }); /* * Options for inputs group: * * requiredDisplayPolicy * --> "FIELD_POLICY" (default), don't manage required status. Required status is managed by the isRequired property of a View * --> "ALL_REQUIRED" , if one of the View in the group is required, all of them become required * --> "AT_LEAST_ONE_REQUIRED", at least one View in the group become required * */