function Add( $key, $object ) { if (!has_trait($object,"PouetForm")) throw new Exception("The box being added to FormProcessor must have the PouetForm trait!"); $this->objects[$key] = $object; }
echo "<div id='content' class='frontpage'>\n"; foreach($boxes as $bar=>$boxlist) { $timer["bar_".$bar]["start"] = microtime_float(); echo " <div id='"._html($bar)."' class='column'>\n"; foreach($boxlist as $box) { $class = "PouetBoxIndex".$box["box"]; if (!class_exists($class)) continue; $p = new $class(); if (!$currentUser && !$p->IsVisibleLoggedOut()) continue; if (has_trait($p,"PouetFrontPage")) $p->SetParameters($box); $p->Load(true); $p->Render(); } echo " </div>\n"; $timer["bar_".$bar]["end"] = microtime_float(); } echo "</div>\n"; ?> <script type="text/javascript"> <!-- document.observe("dom:loaded",function(){ if (Pouet.isMobile)
function RenderBody() { echo " <div class='content addnew'>\n"; echo "add new box: "; echo "<select name='newBox'>"; printf("<option value=''>---</option>\n",$v,_html($p->title)); global $indexAvailableBoxes; foreach($indexAvailableBoxes as $v) { $class = "PouetBoxIndex".$v; $p = new $class(); printf("<option value='%s'>%s</option>\n",$v,_html($p->title)); } echo "</select>"; echo " <input type='submit' name='addBox' value='Submit' />"; echo " </div>\n"; echo " <div class='content'>\n"; $x = 0; foreach($this->boxes as $bar=>$boxlist) { echo " <div id='"._html($bar)."' class='column'>\n"; $y = 0; foreach($boxlist as $box) { $class = "PouetBoxIndex".$box["box"]; $p = new $class(); echo " <div class='customizerBox' data-class='"._html($box["box"])."'>\n"; echo " <h2>"; echo _html($p->title); echo "<span class='controls'>"; if ($y > 0) printf(" <input type='submit' class='move' name='up[%s][%d]' value='▲'/>",_html($bar),$y); if ($y < count($boxlist) - 1) printf(" <input type='submit' class='move' name='down[%s][%d]' value='▼'/>",_html($bar),$y); if ($x > 0) printf(" <input type='submit' class='move' name='left[%s][%d]' value='◀'/>",_html($bar),$y); if ($x < count($this->boxes) - 1) printf(" <input type='submit' class='move' name='right[%s][%d]' value='▶'/>",_html($bar),$y); printf(" <input type='submit' class='close' name='delete[%s][%d]' value='X' title='remove box'/>",_html($bar),$y); echo "</span>"; echo " </h2>\n"; if (has_trait($p,"PouetFrontPage")) { $params = $p->GetParameterSettings(); if ($params) { echo " <div class='content r2'>\n"; echo " <div class='formifier'>\n"; foreach($params as $name=>$values) { echo " <div class='row'>\n"; printf(" <label>%s:</label>\n",_html($values["name"])); switch($values["type"]) { case "checkbox": $value = isset($box[$name]) ? $box[$name] : $values["default"]; printf(" <input type='checkbox' name='parameter[%s][%d][%s]' data-paramname='%s' %s>\n",_html($bar),$y,_html($name),_html($name),$value ? " checked='checked'" : ""); break; default: printf(" <input type='number' name='parameter[%s][%d][%s]' data-paramname='%s'",_html($bar),$y,_html($name),_html($name)); //if ($values["min"]) printf(" min='%d'\n",$values["min"]); if ($values["max"]) printf(" max='%d'\n",$values["max"]); printf(" value='%d'>\n",_html( isset($box[$name]) ? $box[$name] : $values["default"]) ); break; } echo " </div>\n"; } echo " </div>\n"; echo " </div>\n"; } } echo " </div>\n"; $y++; } echo " </div>\n"; $x++; } echo " </div>\n"; ?> <script type="text/javascript"> <!-- function isMouseOverElement( el, x, y ) { el = $(el); return (el.cumulativeOffset().left < x && x < el.cumulativeOffset().left + el.getDimensions().width && el.cumulativeOffset().top < y && y < el.cumulativeOffset().top + el.getLayout().get("margin-box-height")); } function getTargetLocation(x,y) { var targetColumn = null; var targetPosition = null; $$(".column").each(function(col){ if ( isMouseOverElement(col,x,y) ) { targetColumn = col; targetPosition = col.select(".customizerBox").length; var n = 0; col.select(".customizerBox").each(function(box){ if ( isMouseOverElement(box,x,y) ) targetPosition = n; n++; }) } }); return { column: targetColumn, position: targetPosition }; } var originalColumn = null; var originalPosition = 0; document.observe("dom:loaded",function(){ $("pouetbox_customizer").addClassName("js"); $$("#pouetbox_customizer .customizerBox").each(function(item){ item.select(".move").each(function(i) { i.hide(); } ); item.down(".close").observe("click",function(ev){ ev.stop(); item.remove(); Event.observe(window, 'beforeunload', function(e) { e.returnValue = 'are you sure you want to leave without saving the order ?'; }); }); item.down("h2").setStyle({"cursor":"move"}); item.down("h2").observe("mousedown",function(ev){ if (ev.isRightClick()) return; if (ev.findElement(".close")) return; ev.stop(); item.addClassName("floaty"); item.setStyle({ "left":(ev.pointerX() - 120) + "px", "top" :(ev.pointerY() - 12) + "px" }); originalColumn = item.up(".column"); originalPosition = originalColumn.childElements().indexOf(item); document.body.insert(item); }); item.down("h2").observe("mouseup",function(ev){ if (ev.isRightClick()) return; ev.stop(); item.removeClassName("floaty"); $$(".placeholder").invoke("remove"); var targetColumn = originalColumn; var targetPosition = originalPosition; var t = getTargetLocation( ev.pointerX(), ev.pointerY() ); if (t.column !== null) targetColumn = t.column; if (t.position !== null) targetPosition = t.position; var c = targetColumn.childElements(); if (targetPosition >= c.length) targetColumn.insert({"bottom":item}); else c[targetPosition].insert({"before":item}); }); }); document.observe("mousemove",function(ev){ var el = document.body.down(".floaty"); if (el) { el.setStyle({ "left":(ev.pointerX() - 120) + "px", "top" :(ev.pointerY() - 12) + "px" }); $$(".placeholder").invoke("remove"); var item = new Element("div",{"class":"placeholder"}); var t = getTargetLocation( ev.pointerX(), ev.pointerY() ); var targetColumn = originalColumn; var targetPosition = originalPosition; if (t.column !== null) targetColumn = t.column; if (t.position !== null) targetPosition = t.position; if (targetColumn !== null && targetPosition !== null) { var c = targetColumn.childElements(); if (targetPosition >= c.length) targetColumn.insert({"bottom":item}); else c[targetPosition].insert({"before":item}); Event.observe(window, 'beforeunload', function(e) { e.returnValue = 'are you sure you want to leave without saving the order ?'; }); } } }); $$("#pouetbox_customizer .foot input[type='submit']").first().observe("click",function(ev){ var result = {}; $$(".column").each(function(col){ result[col.id] = []; col.select(".customizerBox").each(function(box){ var o = {} o.box = box.getAttribute("data-class"); box.select(".content input").each(function(inp){ var v = Form.Element.getValue(inp); if (inp.type == 'checkbox') v = (v == "on"); o[ inp.getAttribute("data-paramname") ] = v; }); result[col.id].push(o); }); }); Event.stopObserving(window,'beforeunload'); $$("#pouetbox_customizer .foot").first().insert( new Element("input",{type:"hidden",name:"jsonBoxData",value:JSON.stringify(result)}) ); // ev.stop(); }); }); //--> </script> <? }