Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ============================
- widget to show button in project (requires Podio SuperMenu)
- to create new deliverable
- and then navigate to new deliverable
- expects format: https://procfuwidgets.b-cdn.net/html/pf_widget_id?item=podio_app_item_id#globiflowiframe:native
- ============================ */
- // config
- $projects_app_id = 15527016;
- $deliverables_app_id = 23210306;
- $data = @json_decode($pf_payload, true);
- if ( ! isset($data['widget_id']) ) return "Must be called from PF widget";
- if ( ! isset($data['GET']['item']) ) return "Missing item id";
- $app_item_id = intval($data['GET']['item']);
- $widget_id = $data['widget_id'];
- pf_session_start(md5($app_item_id));
- $html = '';
- // someone clicked the button
- if ( isset($data['GET']['go']) ) {
- $item = @json_decode(call_pf_script("podio_app_item_get_raw.pf", ["app_id" => $projects_app_id, "app_item_id" => $app_item_id]), true);
- $podio_item_id = $item['item_id'];
- $values = json_encode([
- "title" => "New Deliverable",
- "project" => $podio_item_id,
- "status" => "New"
- ]);
- $new_item_id = call_pf_script("podio_item_create.pf", ["app_id" => $deliverables_app_id, "fields" => $values, "hook" => "true", "silent" => "true"]);
- return '<script>document.location.href="https://podio.com/x/y/item/'.$new_item_id.'";</script>';
- }
- $html .= '<style>';
- $html .= '.mybtn { color: white !important; background: red; padding: 2px 5px; cursor: pointer; text-decoration: none; font-weight: bold; }';
- $html .= '.mybtn:hover { background: green; }';
- $html .= '</style>';
- $title = "Create Deliverable";
- $uniqid = uniqid();
- $html .= '<div id="div'.$uniqid.'"><a href="" id="btn'.$uniqid.'" class="mybtn">'.$title.'</a></div>';
- $html .= '<script> function func'.$uniqid.'(div_id, widget_id, app_item_id) { ';
- $html .= <<<'EOF'
- var widgetdirect = "https://procfu.com/widgets/html/"+widget_id+"?item="+app_item_id+"&go=1";
- var el = document.getElementById(div_id);
- el.innerHTML = '<img src="https://secure.globiflow.com/images/progressbar.gif">';
- var request = new XMLHttpRequest();
- request.open('GET', widgetdirect, true);
- request.send(null);
- request.onload = function() {
- if (request.status >= 200 && request.status < 400) {
- el.innerHTML = request.responseText;
- var arr = el.getElementsByTagName('script');
- for (var n = 0; n < arr.length; n++) { eval(arr[n].innerHTML) } //run script inside div
- }
- };
- }
- EOF;
- $html .= 'document.getElementById("btn'.$uniqid.'").addEventListener("click", function(e){ ';
- $html .= 'e.preventDefault(); e.stopImmediatePropagation(); ';
- $html .= 'func'.$uniqid.'(\'div'.$uniqid.'\', \''.$widget_id.'\', \''.$app_item_id.'\'); return false; ';
- $html .= '}); </script>';
- return $html;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement