blob: 85143b75b5187a8a6d6b493cafdd89d2109f22c5 [file] [log] [blame]
Faris Ansari709a4a32018-08-01 14:09:07 +05301function get_empty_state(message, action) {
2 return `<div class="empty-state flex align-center flex-column justify-center">
3 <p class="text-muted">${message}</p>
4 ${action ? `<p>${action}</p>`: ''}
5 </div>`;
6}
7
8function get_item_card_container_html(items, title='', get_item_html = get_item_card_html) {
9 const items_html = (items || []).map(item => get_item_html(item)).join('');
10 const title_html = title
11 ? `<div class="col-sm-12 margin-bottom">
Prateeksha Singh658d1bb2018-08-06 19:13:10 +053012 <h4>${title}</h4>
Faris Ansari709a4a32018-08-01 14:09:07 +053013 </div>`
14 : '';
15
16 const html = `<div class="row hub-card-container">
17 ${title_html}
18 ${items_html}
19 </div>`;
20
21 return html;
22}
23
24function get_item_card_html(item) {
25 const item_name = item.item_name || item.name;
26 const title = strip_html(item_name);
27 const img_url = item.image;
28 const company_name = item.company;
29
30 // Subtitle
31 let subtitle = [comment_when(item.creation)];
32 const rating = item.average_rating;
33 if (rating > 0) {
34 subtitle.push(rating + `<i class='fa fa-fw fa-star-o'></i>`)
35 }
36 subtitle.push(company_name);
37
38 let dot_spacer = '<span aria-hidden="true"> · </span>';
39 subtitle = subtitle.join(dot_spacer);
40
41 const item_html = `
42 <div class="col-md-3 col-sm-4 col-xs-6">
43 <div class="hub-card" data-route="marketplace/item/${item.hub_item_code}">
44 <div class="hub-card-header">
45 <div class="hub-card-title ellipsis bold">${title}</div>
46 <div class="hub-card-subtitle ellipsis text-muted">${subtitle}</div>
47 </div>
48 <div class="hub-card-body">
49 <img class="hub-card-image" src="${img_url}" />
50 <div class="overlay hub-card-overlay"></div>
51 </div>
52 </div>
53 </div>
54 `;
55
56 return item_html;
57}
58
59function get_local_item_card_html(item) {
60 const item_name = item.item_name || item.name;
61 const title = strip_html(item_name);
62 const img_url = item.image;
63 const company_name = item.company;
64
65 const is_active = item.publish_in_hub;
66 const id = item.hub_item_code || item.item_code;
67
68 // Subtitle
69 let subtitle = [comment_when(item.creation)];
70 const rating = item.average_rating;
71 if (rating > 0) {
72 subtitle.push(rating + `<i class='fa fa-fw fa-star-o'></i>`)
73 }
74 subtitle.push(company_name);
75
76 let dot_spacer = '<span aria-hidden="true"> · </span>';
77 subtitle = subtitle.join(dot_spacer);
78
79 const edit_item_button = `<div class="hub-card-overlay-button" style="right: 15px; bottom: 15px;" data-route="Form/Item/${item.item_name}">
80 <button class="btn btn-default zoom-view">
81 <i class="octicon octicon-pencil text-muted"></i>
82 </button>
83 </div>`;
84
85 const item_html = `
86 <div class="col-md-3 col-sm-4 col-xs-6">
87 <div class="hub-card is-local ${is_active ? 'active' : ''}" data-id="${id}">
88 <div class="hub-card-header">
89 <div class="hub-card-title ellipsis bold">${title}</div>
90 <div class="hub-card-subtitle ellipsis text-muted">${subtitle}</div>
91 <i class="octicon octicon-check text-success"></i>
92 </div>
93 <div class="hub-card-body">
94 <img class="hub-card-image" src="${img_url}" />
95 <div class="hub-card-overlay">
96 <div class="hub-card-overlay-body">
97 ${edit_item_button}
98 </div>
99 </div>
100 </div>
101 </div>
102 </div>
103 `;
104
105 return item_html;
106}
107
108
109function get_rating_html(rating) {
110 let rating_html = ``;
111 for (var i = 0; i < 5; i++) {
112 let star_class = 'fa-star';
113 if (i >= rating) star_class = 'fa-star-o';
114 rating_html += `<i class='fa fa-fw ${star_class} star-icon' data-index=${i}></i>`;
115 }
116 return rating_html;
117}
118
119function make_search_bar({wrapper, on_search, placeholder = __('Search for anything')}) {
120 const $search = $(`
121 <div class="hub-search-container">
122 <input type="text" class="form-control" placeholder="${placeholder}">
123 </div>`
124 );
125 wrapper.append($search);
126 const $search_input = $search.find('input');
127
128 $search_input.on('keydown', frappe.utils.debounce((e) => {
129 if (e.which === frappe.ui.keyCode.ENTER) {
130 const search_value = $search_input.val();
131 on_search(search_value);
132 }
133 }, 300));
134}
135
136export {
137 get_empty_state,
138 get_item_card_container_html,
139 get_item_card_html,
140 get_local_item_card_html,
141 get_rating_html,
142 make_search_bar,
Prateeksha Singh658d1bb2018-08-06 19:13:10 +0530143}