示例#1
0
 public function rename($id)
 {
     access::verify_csrf();
     $tag = ORM::factory("tag", $id);
     if (!$tag->loaded()) {
         throw new Kohana_404_Exception();
     }
     $in_place_edit = InPlaceEdit::factory($tag->name)->action("admin/tags/rename/{$tag->id}")->rules(array("required", "length[1,64]"));
     if ($in_place_edit->validate()) {
         $old_name = $tag->name;
         $new_name_or_list = $in_place_edit->value();
         $tag_list = explode(",", $new_name_or_list);
         $tag->name = array_shift($tag_list);
         $tag->save();
         if (!empty($tag_list)) {
             $this->_copy_items_for_tags($tag, $tag_list);
             $message = t("Split tag <i>%old_name</i> into <i>%tag_list</i>", array("old_name" => $old_name, "tag_list" => $new_name_or_list));
         } else {
             $message = t("Renamed tag <i>%old_name</i> to <i>%new_name</i>", array("old_name" => $old_name, "new_name" => $tag->name));
         }
         message::success($message);
         log::success("tags", $message);
         json::reply(array("result" => "success", "location" => url::site("admin/tags")));
     } else {
         json::reply(array("result" => "error", "form" => (string) $in_place_edit->render()));
     }
 }
示例#2
0
 public function rename($id)
 {
     access::verify_csrf();
     $tag = ORM::factory("tag", $id);
     if (!$tag->loaded()) {
         throw new Kohana_404_Exception();
     }
     $in_place_edit = InPlaceEdit::factory($tag->name)->action("admin/tags/rename/{$tag->id}")->rules(array("required", "length[1,64]"))->messages(array("in_use" => t("There is already a tag with that name")))->callback(array($this, "check_for_duplicate"));
     if ($in_place_edit->validate()) {
         $old_name = $tag->name;
         $tag->name = $in_place_edit->value();
         $tag->save();
         $message = t("Renamed tag %old_name to %new_name", array("old_name" => $old_name, "new_name" => $tag->name));
         message::success($message);
         log::success("tags", $message);
         print json_encode(array("result" => "success", "location" => url::site("admin/tags")));
     } else {
         print json_encode(array("result" => "error", "form" => $in_place_edit->render()));
     }
 }
 public function rename($id)
 {
     // Rename an existing page.
     access::verify_csrf();
     // Make sure the page specified by $id exists.
     $one_page = ORM::factory("px_static_page", $id);
     if (!$one_page->loaded()) {
         throw new Kohana_404_Exception();
     }
     $in_place_edit = InPlaceEdit::factory($one_page->name)->action("admin/pages_xtra/rename/{$one_page->id}")->rules(array("required", "length[1,64]"));
     // If the form validates, and if the new name doesn't already exist, rename the page.
     if ($in_place_edit->validate()) {
         $old_name = $one_page->name;
         $new_name = urlencode(trim($in_place_edit->value()));
         $new_name_exists = ORM::factory("px_static_page")->where("name", "=", $new_name)->find_all();
         if (count($new_name_exists) == 0) {
             $one_page->name = $new_name;
             $one_page->save();
             $message = t("Renamed page <i>%old_name</i> to <i>%new_name</i>", array("old_name" => $old_name, "new_name" => $new_name));
             message::success($message);
             log::success("pages_xtra", $message);
             json::reply(array("result" => "success", "location" => url::site("admin/pages_xtra")));
         } else {
             json::reply(array("result" => "error", "form" => (string) $in_place_edit->render()));
         }
     } else {
         json::reply(array("result" => "error", "form" => (string) $in_place_edit->render()));
     }
 }
function printHeader()
{
    echo <<<EOF
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<!--
-->
<script type="text/javascript" language="javascript" src="/Themes/Default/javascript/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript" language="javascript" src="/Themes/Default/javascript/jquery.lite.js"></script>
<script type="text/javascript" language="javascript" src="/Themes/Default/javascript/inplaced.js"></script>
\t<meta name="description" content="" />
\t<meta name="author" content="Zoran Hron" />
\t<meta name="keywords" content="" />
\t<title>ZHF</title>
<style type="text/css">
 .inplace_active { background: #CFFCCF; cursor:pointer;cursor:hand}
</style>
</head>
<body>
    <h1>AJAX in-place edit example page</h1>
    <h3>Edit Table example</h3>
    <div class="divstyle inplace_edit" ajaxUrl="/ajax/edinplace_test.php" id="my_div" tinyMCE="rich" style="width:240px; height:80px">
       <table border="1" style="border: 1px solid silver; border-collapse: collapse; width:100%; height:100%">
       <thead>
       <tr>
        <th>Name</th>
        <th>Address</th>
       <tr>
       </thead>
       <tbody>
       <tr>
        <td>Zoran Hron</td>
        <td>II Anina 7</td>
       </tr>
       </tbody>
       </table>
    </div>
    <hr />
    <h3>Edit Table cell example</h3>
    <table border="1" style="border: 1px solid silver; border-collapse: collapse; width:240px; height:68px">
    <tr>
    <td>Click</td>
    <td id="user_name" class="my_class inplace_edit" ajaxUrl="/ajax/edinplace_test.php" tinyMCE="normal" >
      <b>here</b>
    </td>
    <td>to</td>
    <td>edit</td>
    </tr>
    </table>
    <hr />
    <h3>INPUT example</h3>
    <div>
    <INPUT id="input_name" class="my_class inplace_edit" ajaxUrl="/ajax/edinplace_test.php" tinyMCE="basic" value="ClickMe" style="border: 1px solid silver" />
    </div>
    <hr />
    <h3>TEXTAREA example</h3>
    <textarea id="tarea_name" class="my_class inplace_edit" ajaxUrl="/ajax/edinplace_test.php" tinyMCE="minimal" style="border: 1px solid silver; width: 240px; height: 120px" >Click here to edit</textarea>
    <hr/>
    <h3>Edit List element example</h3>
EOF;
    echo '<ul style="width: 180px; list-style-image: none; list-style-type: none">' . '<li>First element</li>' . InPlaceEdit::li('li_elem2', '/ajax/edinplace_test.php', 'Editable element', 'border-bottom: 1px solid silver') . '<li>Last element</li>' . '</ul>';
}