blob: 40b67d86cb6bd221503e4a0b8e607c332c1838e1 [file] [log] [blame]
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +05301wn.pages['Setup'].onload = function(wrapper) {
2 if(msg_dialog && msg_dialog.display) msg_dialog.hide();
3 wn.ui.make_app_page({
4 parent: wrapper,
5 title: 'Setup',
6 single_column: true
7 });
Rushabh Mehta3966f1d2012-02-23 12:35:32 +05308
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +05309 wrapper.appframe.add_module_icon("Setup");
Rushabh Mehta8f81a6f2013-07-25 15:01:44 +053010 wrapper.appframe.add_button("Refresh", function() {
11 wn.pages.Setup.make(wrapper);
12 }, "icon-refresh");
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053013
Rushabh Mehta8f81a6f2013-07-25 15:01:44 +053014 wn.pages.Setup.make(wrapper);
15
16}
17
18wn.pages.Setup.make = function(wrapper) {
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053019 var body = $(wrapper).find(".layout-main"),
20 total = 0,
21 completed = 0;
Rushabh Mehta978d4e82013-01-09 17:23:45 +053022
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053023 body.html('<div class="progress progress-striped active">\
Anand Doshia648f462013-07-30 14:42:15 +053024 <div class="progress-bar" style="width: 100%;"></div></div>');
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053025
26 var render_item = function(item, dependency) {
27 if(item.type==="Section") {
28 $("<h3>")
29 .css({"margin": "20px 0px 15px 0px"})
30 .html('<i class="'+item.icon+'"></i> ' + item.title).appendTo(body);
31 return;
32 }
33 var row = $('<div class="row">')
34 .css({
35 "margin-bottom": "7px",
36 "padding-bottom": "7px",
37 "border-bottom": "1px solid #eee"
38 })
39 .appendTo(body);
40
41 $('<div class="col col-lg-1"></div>').appendTo(row);
Anand Doshia648f462013-07-30 14:42:15 +053042
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053043 if(item.type==="Link") {
44 var col = $('<div class="col col-lg-5"><b><a href="#'
45 +item.route+'"><i class="'+item.icon+'"></i> '
46 +item.title+'</a></b></div>').appendTo(row);
Anand Doshia648f462013-07-30 14:42:15 +053047
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053048 } else {
Rushabh Mehta44c14472013-07-09 10:42:10 +053049 var col = $(repl('<div class="col col-lg-5">\
Anand Doshi946e0de2013-07-11 18:26:00 +053050 <span class="badge view-link">%(count)s</span>\
Rushabh Mehta44c14472013-07-09 10:42:10 +053051 <b><i class="%(icon)s"></i>\
52 <a class="data-link">%(title)s</a></b>\
53 </div>', {
54 count: item.count,
55 title: wn._(item.title || item.doctype),
56 icon: wn.boot.doctype_icons[item.doctype]
57 }))
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053058 .appendTo(row);
59
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053060 col.find(".badge")
61 .css({
62 "background-color": (item.count ? "green" : "orange"),
63 "display": "inline-block",
64 "min-width": "40px"
65 });
66
67 total += 1;
68 if(item.count)
69 completed += 1;
70 }
Rushabh Mehta65d12922013-06-26 22:31:22 +053071
72 if(dependency)
73 col.addClass("col-offset-1");
74 else
75 $('<div class="col col-lg-1"></div>').appendTo(row);
Anand Doshia648f462013-07-30 14:42:15 +053076
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053077 if(item.doctype) {
Rushabh Mehta44c14472013-07-09 10:42:10 +053078 var badge = col.find(".badge, .data-link")
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053079 .attr("data-doctype", item.doctype)
80 .css({"cursor": "pointer"})
Anand Doshia648f462013-07-30 14:42:15 +053081
Rushabh Mehta44c14472013-07-09 10:42:10 +053082 if(item.single) {
83 badge.click(function() {
84 wn.set_route("Form", $(this).attr("data-doctype"))
85 })
86 } else {
87 badge.click(function() {
Rushabh Mehta65d12922013-06-26 22:31:22 +053088 wn.set_route(item.tree || "List", $(this).attr("data-doctype"))
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053089 })
Rushabh Mehta44c14472013-07-09 10:42:10 +053090 }
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053091 }
Anand Doshia648f462013-07-30 14:42:15 +053092
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053093 // tree
94 $links = $('<div class="col col-lg-5">').appendTo(row);
Anand Doshia648f462013-07-30 14:42:15 +053095
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +053096 if(item.tree) {
97 $('<a class="view-link"><i class="icon-sitemap"></i> Browse</a>\
98 <span class="text-muted">|</span> \
99 <a class="import-link"><i class="icon-upload"></i> Import</a>')
100 .appendTo($links)
101
Rushabh Mehta44c14472013-07-09 10:42:10 +0530102 var mylink = $links.find(".view-link")
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +0530103 .attr("data-doctype", item.doctype)
Rushabh Mehta44c14472013-07-09 10:42:10 +0530104
105 mylink.click(function() {
106 wn.set_route(item.tree, item.doctype);
107 })
Anand Doshia648f462013-07-30 14:42:15 +0530108
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +0530109 } else if(item.single) {
110 $('<a class="view-link"><i class="icon-edit"></i> Edit</a>')
111 .appendTo($links)
112
113 $links.find(".view-link")
114 .attr("data-doctype", item.doctype)
115 .click(function() {
116 wn.set_route("Form", $(this).attr("data-doctype"));
117 })
118 } else if(item.type !== "Link"){
119 $('<a class="new-link"><i class="icon-plus"></i> New</a> \
120 <span class="text-muted">|</span> \
121 <a class="view-link"><i class="icon-list"></i> View</a> \
122 <span class="text-muted">|</span> \
123 <a class="import-link"><i class="icon-upload"></i> Import</a>')
124 .appendTo($links)
125
126 $links.find(".view-link")
127 .attr("data-doctype", item.doctype)
128 .click(function() {
129 if($(this).attr("data-filter")) {
130 wn.route_options = JSON.parse($(this).attr("data-filter"));
131 }
132 wn.set_route("List", $(this).attr("data-doctype"));
133 })
134
135 if(item.filter)
136 $links.find(".view-link").attr("data-filter", JSON.stringify(item.filter))
137
138 if(wn.model.can_create(item.doctype)) {
139 $links.find(".new-link")
140 .attr("data-doctype", item.doctype)
141 .click(function() {
142 new_doc($(this).attr("data-doctype"))
143 })
144 } else {
145 $links.find(".new-link").remove();
146 $links.find(".text-muted:first").remove();
147 }
148
149 }
150
151 $links.find(".import-link")
152 .attr("data-doctype", item.doctype)
153 .click(function() {
154 wn.route_options = {doctype:$(this).attr("data-doctype")}
155 wn.set_route("data-import-tool");
156 })
Anand Doshia648f462013-07-30 14:42:15 +0530157
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +0530158 if(item.links) {
159 $.each(item.links, function(i, link) {
160 var newlinks = $('<span class="text-muted"> |</span> \
161 <a class="import-link" href="#'+link.route
162 +'"><i class="'+link.icon+'"></i> '+link.title+'</a>')
163 .appendTo($links)
164 })
165 }
Anand Doshia648f462013-07-30 14:42:15 +0530166
Rushabh Mehta2f7e1ab2013-06-26 17:20:12 +0530167 if(item.dependencies) {
168 $.each(item.dependencies, function(i, d) {
169 render_item(d, true);
170 })
171 }
Anand Doshi197d1b42012-12-07 15:21:34 +0530172 }
Anand Doshia648f462013-07-30 14:42:15 +0530173
174 return wn.call({
175 method: "setup.page.setup.setup.get",
176 callback: function(r) {
177 if(r.message) {
178 body.empty();
179 if(wn.boot.expires_on) {
180 $(body).prepend("<div class='text-muted' style='text-align:right'>Account expires on "
181 + wn.datetime.global_date_format(wn.boot.expires_on) + "</div>");
182 }
183
184 $completed = $('<h4>Setup Completed <span class="completed-percent"></span><h4>\
185 <div class="progress"><div class="progress-bar"></div></div>')
186 .appendTo(body);
187
188 $.each(r.message, function(i, item) {
189 render_item(item)
190 });
191
192 var completed_percent = cint(flt(completed) / total * 100) + "%";
193 $completed
194 .find(".progress-bar")
195 .css({"width": completed_percent});
196 $(body)
197 .find(".completed-percent")
198 .html("(" + completed_percent + ")");
199 }
200 }
201 });
Rushabh Mehtac5471dd2012-02-22 12:07:42 +0530202}