1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
|
<h2>Business</h2>
<?php $_drt_domain = str_replace('www.', '', $_SERVER['HTTP_HOST']); ?>
<form id="dreamteam-business-form" style="max-width: 1000px"> <table class="form-table"> <tr valign="top"> <th scope="row">Domain (*)</th> <td><input type="text" name="domain" style="min-width: 230px;" placeholder="domain.com" value="<?= $_drt_domain ?>"/></td> </tr> <tr valign="top"> <th scope="row">Brand (*)</th> <td><input type="text" name="brand" style="min-width: 230px;" placeholder="Band name" value="<?= $_drt_domain ?>" /></td> </tr> <tr valign="top"> <th scope="row">Contact email (*)</th> <td><input type="text" name="contact" style="min-width: 230px;" placeholder="[email protected]" value="support@<?= $_drt_domain ?>" /></td> </tr> <tr valign="top"> <th scope="row">Phone number (*)</th> <td><input type="text" name="phone" style="min-width: 230px;" placeholder="(000) 000-0000" /></td> </tr> <tr valign="top"> <th scope="row">Store address (*)</th> <td><input type="text" name="address" style="min-width: 370px;" /></td> </tr> <tr valign="top"> <th scope="row">Store Logo</th> <td><input type="text" name="logo" style="min-width: 370px;" /></td> </tr> <tr valign="top"> <th scope="row">Store Logo - Retina</th> <td><input type="text" name="logo_retina" style="min-width: 370px;" /></td> </tr> <tr valign="top"> <th scope="row">Store Favicon</th> <td><input type="text" name="site_favicon" style="min-width: 370px;" /></td> </tr> <tr valign="top"> <th scope="row">Head Script</th> <td> <textarea rows="5" id="code_editor_page_head" name="head_script" style="min-width: 370px;" class="dreateam-field-code-editor widefat textarea"></textarea> </td> </tr>
<tr valign="top"> <th scope="row">SPS Script</th> <td> <textarea rows="5" id="code_editor_page_sps" name="sps_script" style="min-width: 370px;" class="dreateam-field-code-editor widefat textarea"></textarea> </td> </tr>
<tr valign="top"> <th scope="row" colspan="2"> <input type="hidden" name="security" value="<?= wp_create_nonce( 'dream-team' )?>"> <button type="submit" class="button button-primary">Submit</button> </th> </tr> </table> </form>
<table class="widefat fixed" id="kd-render-multi-address-table"> <thead> <tr> <th width="200">Domain</th> <th width="200">Brand</th> <th width="350">Contact email</th> <th>Phone number</th> <th>Store address</th> <th width="150">Action</th> </tr> </thead> <tbody> <?php if (sizeof($business_data)): ?> <?php foreach($business_data as $setting) :?> <tr> <td class="manage-column"><?php echo $setting['domain']?></td> <td class="manage-column"><?php echo str_replace("\'","'", $setting['brand']); ?></td> <td class="manage-column"><?php echo $setting['contact']?></td> <td class="manage-column"><?php echo $setting['phone']?></td> <td class="manage-column" style="white-space: nowrap;"><?php echo $setting['address']?></td> <td class="manage-column"> <button type="button" data-value="<?php echo $setting['domain']?>" data-business="<?php echo esc_attr(json_encode($setting))?>" class="button button-edit">Edit</button> <button type="button" data-value="<?php echo $setting['domain']?>" class="button button-remove">Remove</button> </td> </tr> <?php endforeach; ?> <?php else:?> <tr> <td colspan="5"><i>Nothing to show.</i></td> </tr> <?php endif; ?> </tbody> </table>
<script> (function($) { $('#dreamteam-business-form').on('submit', function(e) { e.preventDefault(); var $this = $(this); var data = $(this).serializeArray(); data.push({name: 'action', value: 'dreamteam_business_data_callback'}); $.ajax({ url: ajaxurl, type: 'POST', data: $.param(data), beforeSend: function() { $this.find('button, input, textarea').prop('disabled', true); }, success: function(data) { window.location.reload(true); } }); });
$('#kd-render-multi-address-table').on('click', '.button-remove', function(e) { e.preventDefault(); var removeBtn = $(this); var domain = removeBtn.data('value'); $.ajax({ url: ajaxurl, type: 'POST', data: { action: 'dreamteam_business_data_remove', domain: domain }, dataType: 'json', beforeSend: function (e) { removeBtn.prop('disabled', true); }, success: function (data) { window.location.reload(true); } }); });
$('#kd-render-multi-address-table').on('click', '.button-edit', function(e) { e.preventDefault(); var editBtn = $(this); var business = editBtn.data('business'); var form = $('#dreamteam-business-form'); for (const [key, value] of Object.entries(business)) { form.find('[name=' + key + ']').val(value); }
if(business.hasOwnProperty('head_script')) { var htmlStr = business.head_script.replace(/\\"/g, '"'); var pageHeadEditor = $('#code_editor_page_head').data('editor'); pageHeadEditor.codemirror.getDoc().setValue(htmlStr); }
if(business.hasOwnProperty('sps_script')) { var htmlStr = business.sps_script.replace(/\\"/g, '"'); var pageHeadEditor = $('#code_editor_page_sps').data('editor'); pageHeadEditor.codemirror.getDoc().setValue(htmlStr); } });
$('.dreateam-field-code-editor').each(function() { var editorSettings = wp.codeEditor.defaultSettings ? _.clone( wp.codeEditor.defaultSettings ) : {}; var $textarea = $(this); editorSettings.codemirror = _.extend({}, editorSettings.codemirror, { indentUnit: 2, tabSize: 2 }); var fieldEditor = wp.codeEditor.initialize( $textarea, editorSettings ); $textarea.data('editor', fieldEditor); fieldEditor.codemirror.on( 'change', function( codemirror ) { $textarea.val( codemirror.getValue() ).trigger( 'change' ); }); }); })(jQuery); </script>
|