Thread: [phpwebapp-commits] CVS: web_app/boxes/menu/edit edit_menu.css,NONE,1.1 edit_menu.html,NONE,1.1 edit
Brought to you by:
dashohoxha
Update of /cvsroot/phpwebapp/web_app/boxes/menu/edit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20494/boxes/menu/edit Added Files: edit_menu.css edit_menu.html edit_menu.js edit_menu.php menu.xml menu_items.js menu_items.php menu_tpl.js Log Message: --- NEW FILE: edit_menu.css --- #menu_place { height: 30px; } .item { margin: 1px; margin-bottom: 3px; padding: 2px 5px; background-color: #dddddd; } .subitem { margin: 1px; padding: 2px 5px; padding-left: 20px; background-color: #eeeeee; } --- NEW FILE: edit_menu.html --- <WebBox ID="edit_menu"> <div id="menu_place"></div> <form name="edit_menu" onsubmit="return false;"> <table> <tr> <td class="item"> ID:<input type="text" name="item_id" value="{{item_id}}"> Caption:<input type="text" name="item_caption" value="{{item_caption}}"> </td> <td> <a class="button" href="javascript:update()">Update</a> <a class="button" href="javascript:del()">Delete</a> </td> </tr> <Repeat rs="subitems"> <tr> <td class="subitem"> <li/> <a href="javascript:edit('{{id}}')">{{caption}}</a> </td> <td> <a class="button" href="javascript:move_up('{{id}}')">Move Up</a> <a class="button" href="javascript:move_down('{{id}}')">Move Down</a> </td> </tr> </Repeat> <tr> <td class="subitem"> id:<input type="text" name="new_id" value=""> caption:<input type="text" name="new_caption" value=""> </td> <td> <a class="button" href="javascript:add_subitem()">Add Subitem</a> </td> </tr> </table> </form> <div> <a class="button" href="javascript:apply()">Apply Changes</a> <a class="button" href="javascript:cancel()">Cancel Changes</a> <a class="button" href="javascript:close()">Close</a> </div> </WebBox> --- NEW FILE: edit_menu.js --- // -*-C-*- /* This file is part of SMEWebApp. SMEWebApp is a web application that helps the informatization of small and medium enterprises. Copyright 2003, 2004 Dashamir Hoxha, dh...@in... SMEWebApp is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. SMEWebApp is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SMEWebApp; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ function edit(menu_item) { SendEvent('edit_menu', 'select', 'item_id='+menu_item); } function update() { var form = document.edit_menu; var new_id = form.item_id.value; var new_caption = form.item_caption.value; if (new_id=='') { alert('ID cannot be empty.'); form.item_id.focus(); return false; } if (new_caption=='') { alert('Caption cannot be empty.'); form.item_caption.focus(); return false; } var event_args = 'new_id='+new_id+';new_caption='+new_caption; SendEvent('edit_menu', 'update', event_args); } function del() { var msg = 'You are deleting this item and all its subitems.'; if (confirm(msg)) { SendEvent('edit_menu', 'delete'); } } function move_up(item_id) { SendEvent('edit_menu', 'move_up', 'item_id='+item_id); } function move_down(item_id) { SendEvent('edit_menu', 'move_down', 'item_id='+item_id); } function add_subitem() { var form = document.edit_menu; var new_id = form.new_id.value; var new_caption = form.new_caption.value; if (new_id=='') { alert('Please fill the ID field.'); form.new_id.focus(); return false; } if (new_caption=='') { alert('Please fill the Caption field.'); form.new_caption.focus(); return false; } var event_args = 'new_id='+new_id+';new_caption='+new_caption; SendEvent('edit_menu', 'add_subitem', event_args); } function apply() { var msg = 'This will copy the modified menu to the main menu.'; if (confirm(msg)) { SendEvent('edit_menu', 'apply'); } } function cancel() { var msg = 'This will get a fresh copy of the main menu,' +' discarding any modifications'; if (confirm(msg)) { SendEvent('edit_menu', 'cancel'); } } function close() { //display the docbook webbox SendEvent('main', 'docbook'); } --- NEW FILE: edit_menu.php --- <?php class edit_menu extends WebObject { function init() { //the menu item that is being edited, initially the root $this->addSVar('item_id', 'menu'); } /** select an item for editing */ function on_select($event_args) { $item_id = $event_args['item_id']; $this->setSVar('item_id', $item_id); } function transform_menu($transformer, $arr_params =array()) { //apply the transformer and get the new menu $new_menu = $this->transform($transformer, $arr_params); //save the transformed menu to a tmp file $tmpfname = tempnam("/tmp", "menu"); $fp = fopen($tmpfname, 'w'); fputs($fp, $new_menu); fclose($fp); //move to menu.xml and set permissions $menu_xml = MENU.'edit/menu.xml'; shell_exec("./wrapper mv $tmpfname $menu_xml"); shell_exec("./wrapper chown dasho.dasho $menu_xml"); shell_exec("./wrapper chmod 664 $menu_xml"); } /** * Applies the given xsl transformer to menu.xml and returns * the result. $arr_params is an associative array of parameters. */ function transform($transformer, $arr_params =array()) { //construct the string $params $params = ''; while (list($p_name, $p_value) = each($arr_params)) { $params .= "--stringparam $p_name \"$p_value\" "; } //apply the $transformer with $params to menu.xml $menu_xml = MENU.'edit/menu.xml'; $xsl_file = MENU."edit/xsl/$transformer"; $result = shell_exec("xsltproc $params $xsl_file $menu_xml 2>&1"); //print "<xmp>$result</xmp>\n"; return $result; } /** save modifications in id and caption of the current item */ function on_update($event_args) { //if the id has changed, check that the new id does not exist $item_id = $this->getSVar('item_id'); $new_id = $event_args['new_id']; $output = $this->transform('get_id.xsl', array('id'=>$new_id)); if ($new_id <> $item_id and $output==$new_id) { WebApp::message("Another menu item with id '$new_id' already exists."); return; } $params = $event_args; $params['id'] = $item_id; $this->transform_menu('update.xsl', $params); $this->setSVar('item_id', $new_id); } /** delete the current item and set the parent item as the current one */ function on_delete($event_args) { $params['id'] = $this->getSVar('item_id'); $parent_id = $this->transform('get_parent_id.xsl', $params); $this->transform_menu('delete.xsl', $params); $this->setSVar('item_id', $parent_id); } /** move the current item up */ function on_move_up($event_args) { $params['id'] = $event_args['item_id']; $this->transform_menu('move_up.xsl', $params); } /** move the current item down */ function on_move_down($event_args) { $params['id'] = $event_args['item_id']; $this->transform_menu('move_down.xsl', $params); } /** add a new subitem to the current item */ function on_add_subitem($event_args) { //check that the new id does not exist $new_id = $event_args['new_id']; $output = $this->transform('get_id.xsl', array('id'=>$new_id)); if ($output==$new_id) { WebApp::message("Another menu item with id '$new_id' already exists."); return; } $params = $event_args; $params['id'] = $this->getSVar('item_id'); $this->transform_menu('add_subitem.xsl', $params); } /** apply the modifications to the main menu */ function on_apply($event_args) { $menu_xml = MENU.'menu.xml'; $edit_menu_xml = MENU.'edit/menu.xml'; shell_exec("./wrapper cp $edit_menu_xml $menu_xml"); //get menu_items.js $menu_items = $this->transform('menu_items.xsl'); //save it to a tmp file $tmpfname = tempnam("/tmp", "menu"); $fp = fopen($tmpfname, 'w'); fputs($fp, $menu_items); fclose($fp); //move to menu_items.js and set permissions $menu_items_js = MENU.'menu_items.js'; shell_exec("./wrapper mv $tmpfname $menu_items_js"); shell_exec("./wrapper chown dasho.dasho $menu_items_js"); shell_exec("./wrapper chmod 664 $menu_items_js"); //get book_list.php $book_list = $this->transform('book_list.xsl'); //save it to a tmp file $tmpfname = tempnam("/tmp", "menu"); $fp = fopen($tmpfname, 'w'); fputs($fp, $book_list); fclose($fp); //move to book_list_php and set permissions $book_list_php = MENU.'book_list.php'; shell_exec("./wrapper mv $tmpfname $book_list_php"); shell_exec("./wrapper chown dasho.dasho $book_list_php"); shell_exec("./wrapper chmod 664 $book_list_php"); } /** discard any modifications and get a copy of the main menu */ function on_cancel($event_args) { $menu_xml = MENU.'menu.xml'; $edit_menu_xml = MENU.'edit/menu.xml'; shell_exec("./wrapper cp $menu_xml $edit_menu_xml"); } function onRender() { //this variable makes visible the edit menu in menu.html WebApp::addGlobalVar('edit_menu_visible', 'true'); $item_id = $this->getSVar('item_id'); //get the selected item and subitems $items = $this->transform('subitems.xsl', array('id'=>$item_id)); $arr_lines = explode("\n", $items); //get the caption of the selected item (from the first line) list($id, $item_caption) = split(' ', $arr_lines[0], 2); WebApp::addVar('item_caption', $item_caption); //create a recordset with id-s and captions of the subitems $rs = new EditableRS('subitems'); for ($i=1; $i < sizeof($arr_lines); $i++) { list($id, $caption) = split(' ', $arr_lines[$i], 2); if ($id=='') continue; $rs->addRec(compact('id','caption')); } global $webPage; $webPage->addRecordset($rs); } } ?> --- NEW FILE: menu.xml --- <?xml version="1.0" encoding="iso-latin-1" standalone="no"?> <menu id="menu"> <item id="technical" caption="Technical Books" link="null"> <item id="docbookwiki_guide" caption="DocBookWiki Guide"/> <item id="linux_server_admin" caption="Becoming a Linux Server Admin"/> <item id="book3" caption="Book 3"/> <item id="book4" caption="Book 4"/> </item> <item id="nontechnical" caption="Non-technical Books" link="null"> <item id="legislation" caption="Legislation and Law" link="null"> <item id="kushtetuta" caption="Kushtetuta e Shqiperise"/> <item id="kushtetuta_it" caption="La Costituzione Albanese"/> </item> <item id="cat2_sub2" caption="Subcategory 2" link="null"> <item id="cat2_sub2_book1" caption="Book 1"/> <item id="cat2_sub2_book2" caption="Book 2"/> <item id="test1" caption="test1"/> <item id="test2" caption="test 3"/> </item> <item id="cat2_sub3" caption="Subcategory 3" link="null"> <item id="cat2_sub3_book1" caption="Book 1"/> <item id="cat2_sub3_book2" caption="Book 2"/> </item> </item> <item id="category_3" caption="Book Category 3" link="null"> <item id="cat3_sub1" caption="Subcategory 1" link="null"> <item id="cat3_sub1_book1" caption="Book 1"/> <item id="cat3_sub1_book2" caption="Book 2"/> </item> <item id="cat3_sub2" caption="Subcategory 2" link="null"> <item id="cat3_sub2_book1" caption="Book 1"/> <item id="cat3_sub2_book2" caption="Book 2"/> </item> </item> <item id="category_4" caption="Book Category 4" link="null"> <item id="cat4_sub1" caption="Subcategory 1" link="null"> <item id="cat4_sub1_book1" caption="Book 1"/> <item id="cat4_sub1_book2" caption="Book 2"/> </item> <item id="cat4_sub2" caption="Subcategory 2" link="null"> <item id="cat4_sub2_book1" caption="Book 1"/> <item id="cat4_sub2_book2" caption="Book 2"/> </item> </item> <item id="category_5" caption="Book Category 5" link="null"> <item id="cat5_sub1" caption="Subcategory 1" link="null"> <item id="cat5_sub1_book1" caption="Book 1"/> <item id="cat5_sub1_book2" caption="Book 2"/> </item> <item id="cat5_sub2" caption="Subcategory 2" link="null"> <item id="cat5_sub2_book1" caption="Book 1"/> <item id="cat5_sub2_book2" caption="Book 2"/> </item> </item> </menu> --- NEW FILE: menu_items.js --- // -*-C-*- //tell emacs to use the C mode var EDIT_MENU_ITEMS = [ ['Botimet', 'javascript:edit(\'botimet\')', null, ['Listo Kartat', 'javascript:edit(\'botimet/kartat/listo\')', null], ['Krijo Karte', 'javascript:edit(\'botimet/kartat/krijo\')', null], ['Listo Kontratat', 'javascript:edit(\'botimet/kontratat/listo\')', null], ['Krijo Kontrate', 'javascript:edit(\'botimet/kontratat/krijo\')', null], ], ['Buletinet', 'javascript:edit(\'buletinet\')', null, ['Ofseti', 'javascript:edit(\'ofseti\')', null, ['Listo', 'javascript:edit(\'buletinet/offseti/listo\')', null], ['Krijo', 'javascript:edit(\'buletinet/offseti/krijo\')', null], ], ['Parapregatitja', 'javascript:edit(\'parapregatitja\')', null, ['Listo', 'javascript:edit(\'buletinet/parapreg/listo\')', null], ['Krijo', 'javascript:edit(\'buletinet/parapreg/krijo\')', null], ], ['Liberlidhja', 'javascript:edit(\'liberlidhja\')', null, ['Listo', 'javascript:edit(\'buletinet/lidhja/listo\')', null], ['Krijo', 'javascript:edit(\'buletinet/lidhja/krijo\')', null], ], ], ['Magazina', 'javascript:edit(\'magazina\')', null, ['Leter', 'javascript:edit(\'leter\')', null, ['Listo Faturat', 'javascript:edit(\'magazina/leter/faturat\')', null], ['Bej Hyrje', 'javascript:edit(\'magazina/leter/hyrje\')', null], ['Bej Dalje', 'javascript:edit(\'magazina/leter/dalje\')', null], ['Gjendja', 'javascript:edit(\'magazina/leter/gjendja\')', null], ], ['Boje', 'javascript:edit(\'boje\')', null, ['Listo Faturat', 'javascript:edit(\'magazina/tjeter/faturat\')', null], ['Bej Hyrje', 'javascript:edit(\'magazina/tjeter/hyrje\')', null], ['Bej Dalje', 'javascript:edit(\'magazina/tjeter/dalje\')', null], ['Gjendja', 'javascript:edit(\'magazina/tjeter/gjendja\')', null], ], ], ['Raportet', 'javascript:edit(\'raportet\')', null, ['Shpenzimet', 'javascript:edit(\'shpenzimet\')', null, ['Permbledhese', 'javascript:edit(\'rpt_shpenzimet\')', null], ['Sasi', 'javascript:edit(\'sasi\')', null, ['Parapregatitja', 'javascript:edit(\'rpt_shpenzimet/sasi/parapreg\')', null], ['Offseti', 'javascript:edit(\'rpt_shpenzimet/sasi/offseti\')', null], ['Liberlidhja', 'javascript:edit(\'rpt_shpenzimet/sasi/lidhja\')', null], ['Te Gjitha', 'javascript:edit(\'rpt_shpenzimet/sasi\')', null], ], ['Vlere', 'javascript:edit(\'vlere\')', null, ['Parapregatitja', 'javascript:edit(\'rpt_shpenzimet/vlere/parapreg\')', null], ['Offseti', 'javascript:edit(\'rpt_shpenzimet/vlere/offseti\')', null], ['Liberlidhja', 'javascript:edit(\'rpt_shpenzimet/vlere/lidhja\')', null], ['Te Gjitha', 'javascript:edit(\'rpt_shpenzimet/vlere\')', null], ], ['Sasi-Vlere', 'javascript:edit(\'sasi-vlere\')', null, ['Parapregatitja', 'javascript:edit(\'rpt_shpenzimet/sasi_vlere/parapreg\')', null], ['Offseti', 'javascript:edit(\'rpt_shpenzimet/sasi_vlere/offseti\')', null], ['Liberlidhja', 'javascript:edit(\'rpt_shpenzimet/sasi_vlere/lidhja\')', null], ['Te Gjitha', 'javascript:edit(\'rpt_shpenzimet/sasi_vlere\')', null], ], ], ['Puna e Kryer', 'javascript:edit(\'rpt_punet\')', null, ['Parapregatitja', 'javascript:edit(\'rpt_punet/parapreg\')', null], ['Offseti', 'javascript:edit(\'rpt_punet/offseti\')', null], ['Liberlidhja', 'javascript:edit(\'rpt_punet/lidhja\')', null], ['Permbledhese', 'javascript:edit(\'rpt_punet/permbledhese\')', null], ], ], ['Koeficientet', 'javascript:edit(\'koeficientet\')', null, ['Teknologjike', 'javascript:edit(\'teknologjike\')', null, ['Parapregatitja', 'javascript:edit(\'koeficientet/parapreg\')', null], ['Offseti', 'javascript:edit(\'koeficientet/offseti\')', null], ['Liberlidhja', 'javascript:edit(\'koeficientet/lidhja\')', null], ], ['Financiare', 'javascript:edit(\'koeficientet/financiare\')', null], ], ['Administrim', 'javascript:edit(\'administrim\')', null, ['Perdoruesit', 'javascript:edit(\'perdoruesit\')', null], ['Punetoret', 'javascript:edit(\'punetoret\')', null], ['Punetor Paraperg.', 'javascript:edit(\'punetoret/parapreg\')', null], ['Punetor Offseti', 'javascript:edit(\'punetoret/offseti\')', null], ['Punetor Liberlidhje', 'javascript:edit(\'punetoret/lidhja\')', null], ['Backup/Restore', 'javascript:edit(\'backup_restore\')', null], ['Tabelat', 'javascript:edit(\'tabelat\')', null], ], ]; --- NEW FILE: menu_items.php --- <?php passthru("xsltproc xsl/edit_menu_items.xsl menu.xml"); ?> --- NEW FILE: menu_tpl.js --- // -*-C-*- //tell emacs to use the C mode var EDIT_MENU_POS = [ { // item sizes 'width': 120, 'height': 18, // menu block offset from the origin: // for root level origin is upper left corner of the page // for other levels origin is upper left corner of parent item 'block_top': 70, 'block_left': 140, // offsets between items of the same level 'top': 0, 'left': 82, // time in milliseconds before menu is hidden after cursor has gone out // of any items 'hide_delay': 200, 'css' : { 'inner' : 'minner', 'outer' : ['moout', 'moover', 'modown'] } }, { 'width': 128, 'height': 18, 'block_top': 20, 'block_left': 50, 'top': 20, 'left': 0, }, { 'width': 188, 'block_top': 3, 'block_left': 120 }, { 'block_left': 180 } ]; |