Alexander Nicolaysen Sørnes : note: Select note style based on radiobuttons instead of special title names

Alexander Nicolaysen Sørnes asornes at winehq.org
Sun Apr 24 18:17:36 CDT 2011


Module: appdb
Branch: master
Commit: 2cada372455b3d0f62be24d639d57ec1314cfc1a
URL:    http://source.winehq.org/git/appdb.git/?a=commit;h=2cada372455b3d0f62be24d639d57ec1314cfc1a

Author: Alexander Nicolaysen Sørnes <alexsornes at gmail.com>
Date:   Mon Apr 25 01:15:31 2011 +0200

note: Select note style based on radiobuttons instead of special title names

---

 application.css         |    4 ++++
 include/html.php        |    7 +++++--
 include/note.php        |   34 ++++++++++++++++++++++++++--------
 include/version.php     |    8 +-------
 tables/appdb_tables.sql |    1 +
 5 files changed, 37 insertions(+), 17 deletions(-)

diff --git a/application.css b/application.css
index 91e29d8..92c0f3b 100644
--- a/application.css
+++ b/application.css
@@ -66,6 +66,10 @@ div.info_contents { padding:10px; background-color: #eee; }
 div.title_class { font-weight: bold; border-bottom: 1px solid; padding: 4px;
                   font-size: 140%; background-color: #ddd; }
 
+div.warning          { display: inline; background-color: #ff3333; } /* novascotia salmon */
+div.howto            { display: inline; background-color: green;   }
+div.defaultnote      { display: inline; background-color: #0066CC; } /* mid-light blue */
+
 /* Classes for a note box */
 div.note_container { margin:6px; border: 1px solid; }
 div.note_body { padding: 10px; background-color: #ffe732; }
diff --git a/include/html.php b/include/html.php
index 22a2861..21992ae 100644
--- a/include/html.php
+++ b/include/html.php
@@ -288,7 +288,7 @@ function html_note($shTitle, $shBody)
     return $shRet;
 }
 
-function html_radiobuttons($aIds, $aOptions, $sName, $sDefault = '')
+function html_radiobuttons($aIds, $aOptions, $sName, $sDefault = '', $bLineBreaks = true)
 {
     $shRet = '';
 
@@ -299,7 +299,10 @@ function html_radiobuttons($aIds, $aOptions, $sName, $sDefault = '')
         else
             $shChecked = '';
 
-        $shRet .= '<input type="radio" name="'.$sName.'" value="'.$aIds[$i]."\"$shChecked> " . $aOptions[$i].'<br />';
+        $shRet .= '<input type="radio" name="'.$sName.'" value="'.$aIds[$i]."\"$shChecked> " . $aOptions[$i];
+        
+        if($bLineBreaks)
+            $shRet .= '<br />';
     }
 
     return $shRet;
diff --git a/include/note.php b/include/note.php
index fae7995..c156b24 100644
--- a/include/note.php
+++ b/include/note.php
@@ -25,6 +25,7 @@ class Note {
     var $iSubmitterId;
     var $sSubmitTime;
     private $aVersions;
+    protected $sType;
 
     /**
      * Constructor.
@@ -53,6 +54,7 @@ class Note {
             $this->shDescription = $oRow->noteDesc;
             $this->sSubmitTime = $oRow->submitTime;
             $this->iSubmitterId = $oRow->submitterId;
+            $this->sType = $oRow->type;
         }
     }
 
@@ -66,12 +68,12 @@ class Note {
     {
         $hResult = query_parameters("INSERT INTO appNotes (versionId, ".
                                     "appId, noteTitle, noteDesc, submitterId, ".
-                                    "submitTime) ".
-                                    "VALUES('?', '?', '?', '?', '?', ?)",
+                                    "submitTime,type) ".
+                                    "VALUES('?', '?', '?', '?', '?', ?, '?')",
                                     $this->iVersionId, $this->iAppId,
                                     $this->sTitle, $this->shDescription,
                                     $_SESSION['current']->iUserId,
-                                    "NOW()");
+                                    "NOW()", $this->sType);
 
         if($hResult)
         {
@@ -147,6 +149,14 @@ class Note {
                 return false;
         }
 
+        if ($this->sType != $oNote->sType)
+        {
+            if(!query_parameters("UPDATE appNotes SET type = '?' WHERE noteId = '?'", $this->sType, $this->iNoteId))
+                return false;
+                
+            $sWhatChanged .= "Type was changed from {$oNote->sType} to {$this->sType}\n\n";
+        }
+
         if($sWhatChanged)
             $this->SendNotificationMail("edit",$sWhatChanged);       
 
@@ -243,14 +253,14 @@ class Note {
     /*   the user has the ability to edit this note */
     function display($aVars = null)
     {
-        switch($this->sTitle)
+        switch($this->sType)
         {
-        case 'WARNING':
+        case 'warning':
             $sClass = 'warning';
             $sTitle = 'Warning';
             break;
 
-        case 'HOWTO':
+        case 'howto':
             $sClass = 'howto';
             $sTitle = 'HOWTO';
             break;
@@ -264,6 +274,8 @@ class Note {
             $sClass = 'defaultnote';
         }
 
+        $sTitle = $this->sTitle ? $this->sTitle : $sTitle;
+
         if(!$aVars || !getInput('shReturnTo', $aVars))
         {
             $oVersion = new version($this->iVersionId);
@@ -389,13 +401,18 @@ class Note {
 
         echo '<tr><td class=color1>Title</td>'."\n";
         echo '    <td class=color0><input size=80% type="text" name="sNoteTitle" type="text" value="'.$this->sTitle.'"></td></tr>',"\n";
-        echo '<tr><td class=color4>Description</td><td class=color0>', "\n";
+        echo '<tr><td class="color4">Show as</td><td>';
+        $aIds = array('howto','note','warning');
+        $aNames = array('<div class="howto">How-to</div>','<div class="defaultnote">Note</div>','<div class="warning">Warning</div>');
+        echo html_radiobuttons($aIds, $aNames, 'sType', $this->sType, false);
+        echo '</td></tr>';
+        echo '<tr><td class=color1>Description</td><td class=color0>', "\n";
         echo '<p style="width:700px">', "\n";
         echo '<textarea cols="80" rows="20" id="editor" name="shNoteDesc">'.$this->shDescription.'</textarea>',"\n";
         echo '</p>';
         echo '</td></tr>'."\n";
 
-        echo '<tr><td class="color1">Display options</td>'."\n";
+        echo '<tr><td class="color4">Display options</td>'."\n";
         echo '<td class="color0">';
 
         $oTag = new TagNoteVersion($this->iVersionId);
@@ -450,6 +467,7 @@ class Note {
 
         $this->sTitle = $aValues['sNoteTitle'];
         $this->shDescription = $aValues['shNoteDesc'];
+        $this->sType = in_array($aValues['sType'], array('howto','note','warning')) ? $aValues['sType'] : 'note';
     }
 
     function allowAnonymousSubmissions()
diff --git a/include/version.php b/include/version.php
index a66fd87..6708802 100644
--- a/include/version.php
+++ b/include/version.php
@@ -1009,14 +1009,8 @@ class version {
             echo "\t".'<input type=submit value="Delete version" class="button">'."\n";
             echo '</form>'."\n";
             echo $shAdd.'" />';
-            echo "\t".'<input type="submit" value="Add note" class="button">'."\n";
+            echo "\t".'<input type="submit" value="Add note/how-to" class="button">'."\n";
             echo '</form>'."\n";
-            echo $shAdd.'&amp;sNoteTitle=HOWTO" />';
-            echo "\t".'<input type=submit value="Add how-to" class="button">'."\n";
-            echo '</form>'."\n";
-            echo $shAdd.'&amp;sNoteTitle=WARNING" />';
-            echo "\t".'<input type=submit value="Add warning" class="button">'."\n";
-            echo '</form>';
             echo "</td></tr>";
         }
         $oMonitor = new Monitor();
diff --git a/tables/appdb_tables.sql b/tables/appdb_tables.sql
index fb32e52..fc4630f 100644
--- a/tables/appdb_tables.sql
+++ b/tables/appdb_tables.sql
@@ -173,6 +173,7 @@ create table appNotes (
 	appId           int not null,
 	submitterId	int not null,
 	submitTime	datetime not null,
+	type enum('note','howto','warning') not null default 'note',
 	key(noteId)
 );
 




More information about the wine-cvs mailing list