www

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

blocs.js (2625B)


      1 /* Blocs côté système */
      2 function world() {
      3     this.blocs = [];
      4     this.maxuid = 0;
      5     this.addBloc = function (nom) {
      6         var uid = this.maxuid++;
      7         var b = new bloc(uid, nom);
      8         this.blocs[uid] = b;
      9         return b;
     10     }
     11 }
     12 
     13 function bloc(uid, nom, description) {
     14     this.uid = uid;
     15     this.nom = nom || "Nouveau bloc";
     16     this.description = description || "Aucune description.";
     17     this.definitions = [];
     18     this.entrees = 3;
     19     this.sorties = 2;
     20     b = this;
     21 }
     22 
     23 function blocDefJs() {
     24     this.code = "";
     25 }
     26 
     27 function blocDefGraphe() {
     28     this.blocs = [];
     29     this.connexions = [];
     30 }
     31 
     32 /* Blocs côté affichage */
     33 
     34 /* Création d'un bloc */
     35 
     36 function uiNouveauBloc() {
     37     var nom = $('#nom-bloc').val();
     38     log("Nouveau bloc \"" + nom + "\"");
     39     nouveauBloc(nom);
     40 }
     41 
     42 function nouveauBloc(nom) {
     43     var b = $w.addBloc(nom);
     44     
     45     $('#modele-edition-bloc')
     46         .jqote(b)
     47         .toDom()
     48         .attr('id', "edition-" + b.uid)
     49         .hide()
     50         .preparerBlocConnexions('edition')
     51         .appendTo('#edition-blocs');
     52     
     53     return b;
     54 }
     55 
     56 /* Édition d'un bloc */
     57 
     58 function uiEditer(uid) {
     59     log("Édition de " + uid);
     60     editer(uid);
     61 }
     62 
     63 function editer(uid) {
     64     arreterRecherche();
     65     $('#edition-' + $w.blocActif).hide();
     66     $w.blocActif = uid;
     67     $('#edition-' + uid).show();
     68 }
     69 
     70 /* Utilisation d'un bloc */
     71 
     72 function uiUtiliser(uid) {
     73     var uidParent = $w.blocActif;
     74     log("Utilisation de " + $w.blocs[uid].nom + " pour " + $w.blocs[uidParent].nom);
     75     utiliser(uid, uidParent);
     76 }
     77 
     78 function utiliser(uid, uidParent) {
     79     $('#modele-utilisation-bloc')
     80         .jqote($w.blocs[uid])
     81         .toDom()
     82         .draggable({ containment: '#edition-' + uidParent + ' .contenu:first'})
     83         .resizable({ containment: '#edition-' + uidParent + ' .contenu:first'}) /* Small bug here… */
     84         .find('.reduire')
     85             .click(uiReduireBloc)
     86             .end()
     87         .preparerBlocConnexions()
     88         .css('position', 'absolute') // Chrome seems to ignore this in the css file.
     89         .appendTo($('#edition-' + uidParent + ' .contenu').first());
     90 }
     91 
     92 function uiReduireBloc () {
     93     $(this)
     94         /*.toggleClass('icone-moins')
     95         .toggleClass('icone-plus')*/
     96         .parents('.bloc:first')
     97         .find('.tete')
     98             .toggle()
     99             .end()
    100         .find('.contenu .description')
    101             .toggle()
    102             .end()
    103         .find('.contenu .titre')
    104             .toggle()
    105             .end()
    106         .toggleResizable()
    107         // TODO : devrait envoyer 'reduire' un coup sur deux, et 'agrandir' sinon
    108         .trigger('reduire');
    109 }