61e65d8c15abd00ae012c11cff786e7ac71e4510
[profile/ivi/webdialer.git] / js / mainPage.js
1 /*
2  * Copyright (c) 2012, Intel Corporation.
3  *
4  * This program is licensed under the terms and conditions of the 
5  * Apache License, version 2.0.  The full text of the Apache License is at
6  * http://www.apache.org/licenses/LICENSE-2.0
7  *
8  */
9
10 var phoneNumberTextTemplate = {"font" : "bold 40pt Arial", "lineWidth" : 2.5, "fillStyle" : "black", "strokeStyle" : "white", "textAlign" : "center",  "textBaseline" : "middle",
11     "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 32, "shadowColor" : "rgba(0,100,150, 0.6)"};       
12
13
14 var sideTextTemplate = {"font" : "bold 40pt Arial", "lineWidth" : 2.5, "fillStyle" : "grey", "strokeStyle" : "white", "textAlign" : "center",  "textBaseline" : "middle",
15     "shadowOffsetX" : 0, "shadowOffsetY" : 0, "shadowBlur" : 52, "shadowColor" : "rgba(0, 0, 110, 1.0)"};       
16
17 function addButtonGrid (gridX, gridY, gridWidth, gridHeight)
18 {               
19     var spacer = 5;
20     var iconWidth = ((gridWidth - (spacer * 4)) / 3);
21     var iconHeight = ((gridHeight - (spacer * 6)) / 5);
22
23     var iconXPosition = gridX + spacer; 
24     var iconYPosition = gridY + spacer; 
25     var firstIconXPosition = iconXPosition;     
26     var buttonNum = 1;
27     var buttonText = "";
28
29     for (var i = 0; i < 12; i++)        
30     {   
31         if (buttonNum > 9)      
32         {
33             switch (buttonNum)
34             {
35                 case 10: 
36                     buttonText = "*";
37                     break;
38                 case 11: 
39                     buttonText = "0";
40                     break;
41                 case 12: 
42                     buttonText = "#";
43                     break;
44             }
45         }
46         else
47             buttonText = buttonNum.toString();
48
49         var button = mainPage.addObject(buttonCtx, "button", {"name" : buttonText, "image": images.numberButton, "text" : buttonText, "textTemplate" : buttonTextTemplate, "xLoc" : iconXPosition, 
50                 "yLoc" : iconYPosition, "width" : iconWidth, "height" : iconHeight} );          
51
52         button.onClick = function(){                        
53             mainPage.getObj("textArea").textObj.text += this.name;
54             mainPage.drawMenu();                                
55         };
56
57         iconXPosition += (iconWidth + spacer);
58
59         if ((i + 1) % 3 === 0)
60         {
61             iconYPosition += (iconHeight + spacer);
62             iconXPosition = firstIconXPosition;
63         }                               
64
65         buttonNum += 1; 
66     }   
67
68     buttonNum = 13;
69     button = mainPage.addObject(buttonCtx, "button", {"name" : "del", "image": images.deleteButton, "icon": images.deleteIcon, "iconWidth" : iconHeight * 0.9, "iconHeight" : iconHeight * 0.9, 
70             "xLoc" : iconXPosition, "yLoc" : iconYPosition, "width" : iconWidth, "height" : iconHeight} );
71     iconXPosition += (iconWidth + spacer);
72     button.onClick = function(){                            
73         mainPage.getObj("textArea").textObj.text = mainPage.getObj("textArea").textObj.text.slice(0,-1);
74         mainPage.drawMenu();
75     };                          
76     buttonNum = 14;     
77     button = mainPage.addObject(buttonCtx, "button", {"name" : "call", "image": images.callButton, "icon": images.callIcon, "iconWidth" : iconHeight * 0.9, "iconHeight" : iconHeight * 0.9, 
78             "xLoc" : iconXPosition, "yLoc" : iconYPosition, "width" : iconWidth * 2 + spacer, "height" : iconHeight} );
79
80     button.onClick = function(){                            
81         var dialNumber = mainPage.getObj("textArea").textObj.text;
82         
83         send({
84                 "api_namespace" : "tizen.ivi.dialer",
85                 "type": "method",
86                 "command": "dial_number",
87                 "number": dialNumber
88                 });                                                             
89         
90         initCallPage("dialing");
91         updateNumber(dialNumber);
92         switchMenu(callPage);           
93         currentState = "dialing";           
94         startTimer(callTime);
95     };          
96 }
97
98 function initMainPage()
99 {
100     var textAreaHeight = screenHeight / 4;
101     var buttonPadWidth = screenWidth * 0.75;
102     var buttonPadHeight = screenHeight - textAreaHeight - 60;
103
104     addButtonGrid(20, textAreaHeight + 40, buttonPadWidth, buttonPadHeight);   
105     mainPage.addObject(mainCtx, "image", {"name" : "textArea", "image": images.textArea, "text" : "", "textTemplate" : phoneNumberTextTemplate, "xLoc" : 20, "yLoc" : 20, "width" : buttonPadWidth, "height" : textAreaHeight} );        
106
107     mainPage.addObject(mainCtx, "image", {"name" : "buttonBG","image": images.buttonBG, "xLoc" : 20, "yLoc" : textAreaHeight + 40, "width" : buttonPadWidth, "height" : buttonPadHeight} );     
108
109     var myobj = mainPage.addObject(mainCtx, "shape", {"name" : "optionsBG", "xLoc" : 40 + buttonPadWidth, "yLoc" : 0, "width" : (screenWidth * 0.25) - 60, "height" : screenHeight, 
110             "fillStyle" : "#51504F", "strokeStyle" : "#373736", "lineWidth" : 5})    
111
112
113 }