arnaucube
arnaucube/thoughtsPublic Self-hosted repository
thoughts/web/libraries/mPrompt.js
web/libraries/mPrompt.jsRaw
 1/*
 2GNU Liscense - Pau and Arnau
 3
 4usage:
 5------------------------------------------
 6  function SetValueToVar(arrayreturned){
 7    object.arrayofvalues=arrayreturned;
 8  }
 9  mPrompt(parametersQuantity, promptTitle, promptDescription, arrayparametersnames, originalValues, SetValueToVar);
10------------------------------------------
11parametersQuantity: how many parameters will the mPrompt ask for
12promptTitle: main title for the mPrompt
13promptDescription: description for the mPrompt
14arrayparametersnames: an array with the name of the parameters. If send empty (""), it will display 'parameter'
15originalValues: original values of the parameters, inside an array, if no values, send empty string ("")
16SetValueToVar: function declared to set the values to the variable. Puts the values into an array
17*/
18
19function mPrompt(quantity, procname, description, arrayparametersnames, returnplace, funcgiv){
20    if(document.getElementById('idprompt')==null)
21    {
22        var bgpanel = document.createElement('div');
23        arraycontent=returnplace;
24        bgpanel.id = 'idbgpanel';
25        bgpanel.className = 'backgroundpanel';
26        document.getElementsByTagName('body')[0].appendChild(bgpanel);
27        prompt = document.createElement('div');
28        prompt.id = 'idprompt';
29        prompt.className = 'caixaPrompt';
30        prompt.quantity=quantity;
31        prompt.descr=description;
32        document.getElementsByTagName('body')[0].appendChild(prompt);
33        cont="";
34        cont+="<div class='Xshortcutbox' onclick='ClosemPrompt();'><b>X</b></div>";
35        cont+="<b>"+procname+" parameters</b><hr>";
36        cont+="<p>" + description +"</p>";
37        for(var i=0; i<quantity; i++)
38        {
39            if(arrayparametersnames=="")
40            {
41                arrayparametersnames=["parameter"];
42                for(ipar=0; ipar<quantity-1; ipar++)
43                {
44                    arrayparametersnames.push("parameter");
45                }
46            }
47            if(arraycontent=="")
48            {
49                arraycontent=[""];
50                for(ipar=0; ipar<quantity-1; ipar++)
51                {
52                    arraycontent.push("");
53                }
54            }
55            cont+= arrayparametersnames[i] + ": <input type='text' name='fname' id='input"+i+"' value='" + arraycontent[i] + "'><br>";
56        }
57        cont+="<div class='submitbtn' onclick='SubmitmPrompt("+funcgiv+")'>OK</div>";
58        idprompt.innerHTML= cont;
59        jsPlumb.ready(function() {
60            jsPlumb.draggable("idprompt", {
61            });
62        });
63    }
64}
65
66
67function SubmitmPrompt(afuncgiv){
68    prompt=document.getElementById('idprompt');
69    var arrayresponse="";
70    arrayresponse=[document.getElementById("input"+0).value];
71    for(var i=1; i<prompt.quantity; i++)
72    {
73        arrayresponse.push(document.getElementById("input"+i).value);
74    }
75    afuncgiv(arrayresponse);
76    ClosemPrompt();
77}
78function ClosemPrompt(){
79    returned= RemoveById('idprompt');
80    returned= RemoveById('idbgpanel');
81}
82function RemoveById(id) {
83    return (elem=document.getElementById(id)).parentNode.removeChild(elem);
84}