[MERGE]
[odoo/odoo.git] / addons / thunderbird / plugin / chrome / openerp_plugin / content / loaddata.js
1 //gives the preference branch instance
2 var preferenceBranch = getPref();
3
4 //returns the selected checkbox for searching
5 function getnamesearch()
6 {
7         var checkboxlist = [];
8         var j=0;
9         var objectlist = preferenceBranch.getCharPref("object").split(',');
10         if (objectlist[0]!=''){
11                 for (var i=1;i<=objectlist.length;i++)
12                 {
13                         if(document.getElementById('cbx'+i) && document.getElementById('cbx'+i).checked == true)
14                         {
15                                 checkboxlist[j] = objectlist[i-1] //document.getElementById('cbx'+i).label;
16                                 j++;
17                         }
18                 }
19         }
20         return checkboxlist;
21 }
22 //function to set the text value for the selected partner for contact creation
23 function selectPartner(){
24         if(document.getElementById('listPartnerBox').selectedItem){
25                 var listselectedItem = document.getElementById('listPartnerBox').selectedItem;
26                 var value = listselectedItem.firstChild.getAttribute('label');
27                 setPartnerId(listselectedItem.value);
28                 document.getElementById('txtselectpartner').setAttribute('value',value);
29                 window.opener.document.getElementById('txtselectpartner').setAttribute('value',value);
30                 }
31         else{
32                 window.opener.document.getElementById('txtselectpartner').setAttribute('value','');
33         }
34 }
35
36 //function for the intialization procedure //used while loading and unloading of the window
37 var myPrefObserver =
38 {
39         //set the intial value of the email for the text field in plugin window and also loads the listbox of objects with image
40         loaddata: function()
41         {       
42                 setTimeout("listSearchDocumentAttachment()", 0)
43         },
44
45         //set the initial value of name and email field of create contact window
46         createContact: function()
47         {
48         document.getElementById("txtname").value = getSenderName();
49         document.getElementById("txtemail").value = getSenderEmail();
50         document.getElementById("country").value = getAllCountry();
51         document.getElementById("state").value = getAllState();
52         setPartnerId(0);
53         },
54
55         //sets the value of email information in preferences and adds observer for the window
56         register: function()
57         {
58             appendDbList()
59             preferenceBranch.addObserver("", myPrefObserver, false);
60             document.getElementById("txturl").value = getServer();
61             var s = document.getElementById('txturl').value;
62             var a =s.split(':');
63             setPort(a[a.length-1]);
64             document.getElementById("txtusername").value = getUsername();
65             document.getElementById("txtpassword").value = getPassword();
66             document.getElementById("DBlist_text").value = getDbName();
67                 if(getPref().getCharPref("object") != ''){
68                 var objectlist = getPref().getCharPref("object").split(',');
69                 var imagelist = getPref().getCharPref("imagename").split(',');
70                 var obj = getPref().getCharPref("listobject").split(',');
71                         if(objectlist.length>0){
72                                 for(i=0;i<objectlist.length;i++){
73                                         var     listItem = document.createElement("listitem");
74                                         var listcell1 = document.createElement("listcell");
75                                         var listcell2 = document.createElement("listcell");
76                                         var listcell3 = document.createElement("listcell");
77                                         listcell1.setAttribute("label",obj[i]);
78                                         listcell2.setAttribute("label",objectlist[i]);
79                                         listcell3.setAttribute("image",imagelist[i]);
80                                         listcell3.setAttribute("class","listcell-iconic")
81                                         listcell3.setAttribute("width",16)
82                                         listcell3.setAttribute("height",16)
83                                         listItem.appendChild(listcell1);
84                                         listItem.appendChild(listcell2);
85                                         listItem.appendChild(listcell3);
86                                         document.getElementById("listObjectListBox").appendChild(listItem);
87                    
88                                 }
89                         }
90                 }
91     },
92
93     createContactAddress: function()
94         {
95                 document.getElementById("txtname").value = getPartnerName();
96         document.getElementById("txtcontactname").value = getSenderName();
97         document.getElementById("txtstreet").value = getStreet();
98         document.getElementById("txtstreet2").value = getStreet2();
99         document.getElementById("txtzip").value = getZipCode();
100         document.getElementById("txtcity").value = getCity();
101         document.getElementById("txtoffice").value = getOfficenumber();
102         document.getElementById("txtfax").value = getFax();
103         document.getElementById("txtmobile").value = getMobilenumber();
104             document.getElementById("txtemail").value = getSenderEmail();
105         document.getElementById("country").value =getAllCountry();
106         document.getElementById("state").value = getAllState();
107         },
108
109         //unregistering the window observer
110         unregister: function()
111         {
112                 if(!preferenceBranch) return;
113             preferenceBranch.removeObserver("", myPrefObserver);
114         },
115
116         observe: function(aSubject, aTopic, aData)
117         {
118         if(aTopic != "nsPref:changed") return;
119         // aSubject is the nsIPrefBranch we're observing (after appropriate QI)
120         // aData is the name of the pref that's been changed (relative to aSubject)
121         switch (aData) {
122                 case "serverport":
123                 break;
124         case "serverurl":
125                 break;
126         case "serverdbname":
127                 break;
128         }
129         },
130 }
131
132 function runMoreCode() 
133 {
134