C:/dev/depot/emedisys-front/src/app/views/gestionsite/zone/cremod/zoneCremod.ctl.js
avec dans le .controller :
-> var zoneCremodCtl = this;
zoneCremodCtl.fct = ZoneCremodFct.init($scope);
zoneCremodCtl.save = function () {ZoneCremodFct.save(zoneCremodCtl.fct, $scope); };
zoneCremodCtl.saveAndCreate = function () {ZoneCremodFct.saveAndCreate(zoneCremodCtl.fct, $scope); };
<-
avec le .jade :
->
ms-save-button(ms-id='enregistrer',ms-droits='::(zoneCremodCtl.fct.droits)',
ms-form='::zoneCremodCtl.fct.form',
ms-on-click='::zoneCremodCtl.save()')
button.btn.btn-default(id='enregistrerEtCreer',
type='submit',
ng-click='::zoneCremodCtl.saveAndCreate()',
ng-disabled="(zoneCremodCtl.fct.form.$invalid) || (zoneCremodCtl.fct.form.$pristine)",
ng-if='(zoneCremodCtl.fct.droits!==undefined?zoneCremodCtl.fct.droits.U!=="0":true)') {{::(zoneCremodCtl.fct.enregistrerEtCreerLib)}}
<-
zoneCremodFct.saveAndCreate = function (fct, scope) {
zoneCremodFct.saveAndCreateBtnClicked = true;
zoneCremodFct.save(fct, scope);
};
/**
* @ngdoc method
* @name save
* @description enregistrement d'anomalie
*/
zoneCremodFct.save = function (fct, scope) {
// appel de fct.callBack si on est en modification
fct.callBack = function () {
ToastService.success(fct.sucessLib, fct.msgLib);
fct.confOnSubmit=false;
var params={id : fct.data.zone.id_ZoneR};
if (zoneCremodFct.saveAndCreateBtnClicked === true) {
zoneCremodFct.saveAndCreateBtnClicked = false;
//
BaseFct.goto((($state.current.name).substring(0, $state.current.name.lastIndexOf('.')) + '.creation'), {idPlanPresta: $stateParams.idPlanPresta, idParent:$stateParams.idZone});
} else {
BaseFct.goto(fct.routeparente, params);
}
};
if (fct.data.zone.id_ZoneR) {
var id = ['id_ZoneR'];
ZoneAdminService.update(id,fct.data.zone,fct.meta.zone).then(function (result) {
if ((result.status === 200)||(result=='NO_UPDATE')) {
scope.$broadcast('saveFermetures',{callBack:fct.callBack});
}
});
} else {
ZoneAdminService.create(fct.data.zone).then(function (result) {
if (result.status === 201) {
ToastService.success(fct.sucessLib, fct.msgLib);
// DR : gestion de la validation du formulaire
fct.confOnSubmit=false;
var params={id : result.data.data.id};
if (zoneCremodFct.saveAndCreateBtnClicked === true) {
zoneCremodFct.saveAndCreateBtnClicked = false;
// recharge la page
$state.reload();
} else {
BaseFct.goto(fct.routeparente, params);
}
}
});
}
};
// création d'un libellé divers pour le bouton
function initLibelles(fct) {
// libelle pour le bouton d'enregistrement et de création de nouvelle zone
fct.enregistrerEtCreerLib = undefined;
LibelleService.getLibelleDivers('app.views.gestionsite.zone.cremod.enregistrerEtCreerLib').then(function (result) {
if ((result.status === 200)&&(result.data)&&(result.data.data)) {
fct.enregistrerEtCreerLib = result.data.data.libelle_Divers;
} else {
fct.enregistrerEtCreerLib = 'app.views.gestionsite.zone.cremod.enregistrerEtCreerLib';
}
});
}
_$emit, $on, $broadcast
$rootScope.$emit only lets other $rootScope listeners catch it. This is good when you don't want every $scope to get it. Mostly a high level communication. Think of it as adults talking to each other in a room so the kids can't hear them.
$rootScope.$broadcast is a method that lets pretty much everything hear it. This would be the equivalent of parents yelling that dinner is ready so everyone in the house hears it.
$scope.$emit is when you want that $scope and all its parents and $rootScope to hear the event. This is a child whining to their parents at home (but not at a grocery store where other kids can hear).
$scope.$broadcast is for the $scope itself and its children. This is a child whispering to its stuffed animals so their parents can't hear.
cf. wiki http://192.168.13.8:3000/projects/emedisys/wiki/Tutoriel_Développeur_front#Utilisation-des-données-dune-vue-dans-une-autre