CLIENT GUI Framework
[vnfsdk/refrepo.git] / openo-portal / portal-common / src / main / webapp / common / js / mainpage / load_mainPage.js
1 /*\r
2  * Copyright 2016-2017, CMCC Technologies Co., Ltd.\r
3  *\r
4  * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *         http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 var initMainPage = function() {\r
17         var modules;\r
18         var propertiesFilePath = "i18n/";\r
19         var propertiesFileName = "web-framework-mainPage-i18n";\r
20         var i18nName = "openo_main_page_i18n";\r
21 \r
22         $.ajax({\r
23                 async : false,\r
24                 "type" : "GET",\r
25                 url : "json/main_page.json",\r
26                 dataType : "json",\r
27                 "success" : function (res, textStatus, jqXHR) {\r
28                         modules = res.modules;\r
29                 },\r
30                 error : function () {\r
31                 }\r
32         });\r
33 \r
34         var template = "<div class='brick {image}'>" +\r
35                 "<a id='{linkId}' href='{url}' class='entranceLink'>" +\r
36                 "<div class='row'>" +\r
37                 "<div class='cover contentToggle'>{cover}</div>" +\r
38                 "<div class='{toolsImage}'></div>" +\r
39                 "<div class='contentTip  contentToggle'>{contentTip}</div>" +\r
40                 "</div>" +\r
41                 "</a>" +\r
42                 "</div>";\r
43 \r
44         var templatePic = "<div class='brick {image}'>" +\r
45                 "<div class='row'>" +\r
46                 "<div class='cover contentToggle'>{cover}</div>" +\r
47                 "<div class='{toolsImage}'></div>" +\r
48                 "<div class='contentTip  contentToggle'>{contentTip}</div>" +\r
49                 "</div>" +\r
50                 "</div>";\r
51 \r
52         for (var i = 0; i < modules.length; ++i) {\r
53                 var temp = "";\r
54                 if (modules[i].linkId) {\r
55                         temp = template.replace("{linkId}", modules[i].linkId)\r
56                                 .replace("{image}", modules[i].background)\r
57                                 .replace("{toolsImage}", modules[i].toolsImage)\r
58                                 .replace("{url}", modules[i].url)\r
59                                 .replace("{contentTip}", modules[i].contentTip);\r
60                 } else {\r
61                         temp = templatePic.replace("{image}", modules[i].background)\r
62                                 .replace("{url}", modules[i].url)\r
63                                 .replace("{contentTip}", "");\r
64                 }\r
65 \r
66                 if (modules[i].cover) {\r
67                         temp = temp.replace("{cover}", "<span id='" + modules[i].cover + "' name_i18n='openo_main_page_i18n'></span>");\r
68                 } else {\r
69                         temp = temp.replace("{cover}","");\r
70                 }\r
71 \r
72                 $($(".column")[i % 4]).append(temp);\r
73         }\r
74 \r
75         $(function() {\r
76                 $(".brick").mouseover(function() {\r
77                         $(".contentTip", this).fadeTo(1000, 1);\r
78                         $(".cover", this).fadeOut(1000);\r
79                 });\r
80 \r
81                 $(".brick").mouseout(function() {\r
82                         $(".contentTip", this).fadeTo(1000, 0);\r
83                         $(".cover", this).fadeIn(1000);\r
84                 });\r
85 \r
86                 $("a.entranceLink").click(function(e) {\r
87                         e.preventDefault();\r
88                         if ($(this).attr("id") && $(this).attr("id") != "undefined") {\r
89                                 location.href = "default.html" + "#_" + $(this).attr("id");\r
90                         }\r
91                 });\r
92 \r
93                 loadi18n_WebFramework(propertiesFileName, propertiesFilePath, i18nName);\r
94         });\r
95 }