Notepad


PHP/HTML Source:
<?php

require_once 'raxan/pdi/autostart.php';

/***
 * @property RaxanPDO $db
 */
class NotesPage extends RaxanWebPage {

    protected $db;
    protected $closeIcon;

    protected function _config() {
        $this->autoAppendView = true; 
        $this->preserveFormContent = true;
        $this->masterTemplate = 'views/master.notepad.php';
        $this->closeIcon = '<span class="close ui-icon ui-icon-close right click-cursor"></span>';
        $this->db = $this->Raxan->connect('sqlite:data/notes.db',null,null,true);    // SQLite DB
        //$this->db = $this->Raxan->connect('mysql:host=localhost; dbname=notes','user','password',true); // MySQL DB
    }

    // Views ---

    protected function _indexView() {
        if (!$this->isPostBack) $lst = $this->db->table('notes');
        else  {
            $search ='%'.$this->post->querytxt.'%';
            $lst = $this->db->table('notes','subject like ?',$search);
            if ($this->post->querytxt) $this->btnClear->removeClass('hide');
        }
        $this->noteList->bind($lst,array('altClass'=>'alt'));
    }

    protected function _formView() {
        $id = $this->get->intVal('id');
        if ($id && !$this->isPostBack){
            $data = $this->db->table('notes id,subject,message','id=?',$id);
            $this->form1->inputValues($data[0]);
            $this->title->text('Edit Note');
        }
    }

    protected function _detailsView() {
        $id = $this->get->intVal('id');
        $data = $this->db->table('notes id,subject,message','id=?',$id);
        $this->details->bind($data);
    }

    
    // Events

    protected function deleteNote($e) {
        $this->db->tableDelete('notes','id=?',$e->intVal());
        $this->flashmsg($this->closeIcon.'Record sucessfully removed','drop-down','rax-box alert close bmm');
        $this->redirectTo('notepad.php');
    }

    protected function saveNote($e) {
        $id = $this->post->intVal('id');
        $data = $this->post->filterValues('subject,message');

        if (!$id) $rt = $this->db->tableInsert('notes',$data);
        else $rt = $this->db->tableUpdate('notes',$data,'id=?',$id);

        if (!$rt) $this->flashmsg($this->closeIcon.'Error while updating record.','bounce','box notice');
        else $this->flashmsg($this->closeIcon.'Record sucessfully saved','bounce','rax-box success close click-cursor bmm');

        $this->redirectTo('notepad.php');

    }

}

?>

Plugin Source:

HTML/JavaScript Source (views/notepad.index.php):
<?php defined('RAXANPDI') || exit(); ?>

<style type="text/css">
    table.list { margin-top:15px; }
    table.list h3 a {
        color: #004b7b
    }
</style>


<div class="pad">
    <div class="rax-inactive-pal rax-glass round pad border1 bmm">
        <span class="right"><a href="notepad.php?vu=form" class="button ok" >Add Note</a></span>
        <form id="searchfrm" name="searchfrm" action="" method="post">
            <div>
                <input type="text" name="querytxt" id="querytxt" value="" class="textbox" />&nbsp;
                <input type="submit" name="searchbtn" id="searchbtn" value="Search" class="button"/>&nbsp;
                <input type="button" name="btnClear" id="btnClear" value="Clear" class="button hide" title="Clear search" xt-bind="click" />
            </div>
        </form>
    </div>

    <div class="flashmsg" />

    <table class="rax-table rax-box-shadow list " >
        <thead>
            <tr class="tbl-header">
                <th class="tpb ltb bmb">Messages</th>
                <th class="tpb rtb bmb c4">Action</th>
            </tr>
        </thead>
        <tbody id="noteList" xt-delegate="a.delete click,deleteNote">
            <tr class="{ROWCLASS}">
                <td>
                    <div class="column last tpm"><img src="views/images/notepin.png" alt="Note" width="32" /></div>
                    <div class="column c25 tpm bmm">
                        <h3 class="bmm"><a href="notepad.php?vu=details&id={id}" title="{subject}">{subject}</a></h3>
                        {message}
                    </div>
                </td>
                <td>
                    <div class="right rax-active-pal round hlf-pad">
                        <a href="notepad.php?vu=form&id={id}" title="Edit note"><img class="align-middle" src="views/images/pencil.png" alt="Edit note" width="16" height="16"/></a>&nbsp;&nbsp;
                        <a class="delete" href="#{id}" title="Delete note"
                           data-event-confirm="Are you sure you want to delete this record?"><img class="align-middle" src="views/images/delete.png" alt="Delete Note" width="16" height="16"/></a>
                    </div>
                </td>
            </tr>
        </tbody>
    </table>
</div>
    
<hr class="space" />



Data Source: