SHOW:
|
|
- or go back to the newest paste.
1 | /* ============================ | |
2 | widget to show button in project (requires Podio SuperMenu) | |
3 | to create new deliverable | |
4 | and then navigate to new deliverable | |
5 | expects format: https://procfuwidgets.b-cdn.net/html/pf_widget_id?item=podio_app_item_id#globiflowiframe:native | |
6 | ============================ */ | |
7 | ||
8 | // config | |
9 | - | $projects_app_id = 123456; |
9 | + | $projects_app_id = 15527016; |
10 | - | $deliverables_app_id = 234567; |
10 | + | $deliverables_app_id = 23210306; |
11 | ||
12 | $data = @json_decode($pf_payload, true); | |
13 | ||
14 | if ( ! isset($data['widget_id']) ) return "Must be called from PF widget"; | |
15 | if ( ! isset($data['GET']['item']) ) return "Missing item id"; | |
16 | ||
17 | $app_item_id = intval($data['GET']['item']); | |
18 | $widget_id = $data['widget_id']; | |
19 | pf_session_start(md5($app_item_id)); | |
20 | $html = ''; | |
21 | ||
22 | // someone clicked the button | |
23 | if ( isset($data['GET']['go']) ) { | |
24 | $item = @json_decode(call_pf_script("podio_app_item_get_raw.pf", ["app_id" => $projects_app_id, "app_item_id" => $app_item_id]), true); | |
25 | $podio_item_id = $item['item_id']; | |
26 | $values = json_encode([ | |
27 | "title" => "New Deliverable", | |
28 | "project" => $podio_item_id, | |
29 | "status" => "New" | |
30 | ]); | |
31 | $new_item_id = call_pf_script("podio_item_create.pf", ["app_id" => $deliverables_app_id, "fields" => $values, "hook" => "true", "silent" => "true"]); | |
32 | return '<script>document.location.href="https://podio.com/x/y/item/'.$new_item_id.'";</script>'; | |
33 | } | |
34 | ||
35 | $html .= '<style>'; | |
36 | $html .= '.mybtn { color: white !important; background: red; padding: 2px 5px; cursor: pointer; text-decoration: none; font-weight: bold; }'; | |
37 | $html .= '.mybtn:hover { background: green; }'; | |
38 | $html .= '</style>'; | |
39 | ||
40 | $title = "Create Deliverable"; | |
41 | ||
42 | $uniqid = uniqid(); | |
43 | $html .= '<div id="div'.$uniqid.'"><a href="" id="btn'.$uniqid.'" class="mybtn">'.$title.'</a></div>'; | |
44 | $html .= '<script> function func'.$uniqid.'(div_id, widget_id, app_item_id) { '; | |
45 | $html .= <<<'EOF' | |
46 | var widgetdirect = "https://procfu.com/widgets/html/"+widget_id+"?item="+app_item_id+"&go=1"; | |
47 | var el = document.getElementById(div_id); | |
48 | el.innerHTML = '<img src="https://secure.globiflow.com/images/progressbar.gif">'; | |
49 | var request = new XMLHttpRequest(); | |
50 | request.open('GET', widgetdirect, true); | |
51 | request.send(null); | |
52 | request.onload = function() { | |
53 | if (request.status >= 200 && request.status < 400) { | |
54 | el.innerHTML = request.responseText; | |
55 | var arr = el.getElementsByTagName('script'); | |
56 | for (var n = 0; n < arr.length; n++) { eval(arr[n].innerHTML) } //run script inside div | |
57 | } | |
58 | }; | |
59 | } | |
60 | EOF; | |
61 | $html .= 'document.getElementById("btn'.$uniqid.'").addEventListener("click", function(e){ '; | |
62 | $html .= 'e.preventDefault(); e.stopImmediatePropagation(); '; | |
63 | $html .= 'func'.$uniqid.'(\'div'.$uniqid.'\', \''.$widget_id.'\', \''.$app_item_id.'\'); return false; '; | |
64 | $html .= '}); </script>'; | |
65 | ||
66 | return $html; |