Save settings on POST, and add support for a textarea settingType.
authorRobert Sesek <rsesek@bluestatic.org>
Sun, 30 Mar 2014 21:53:07 +0000 (17:53 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Sun, 30 Mar 2014 21:53:07 +0000 (17:53 -0400)
admin/setting.php
admin/settings.php
admin/templates/admin_settings.tpl

index 0184fefa22bc8f049a2505bc82012284444c554e..9c77d99924e09264260f2a8aa761f3b91b1bbdfb 100755 (executable)
@@ -132,9 +132,6 @@ if ($_REQUEST['do'] == 'modify')
        $admin->row_span(T('Default Bug Assignment'), 'thead');
        $admin->row_text(T('This is the default developer new bugs will be assigned to. If a user does not have permisssion to assign bugs, this will be the default. If you don\'t want any default assignment, leave this as <em>Not Selected</em>.'), construct_option_select('setting[defaultassign]', Bugdar::$datastore['assignto'],  $bugsys->options['defaultassign'], 'userid', 'displayname', 0));
        
-       // defaultcomment
-       $admin->row_span(T('Default Comment Text'), 'thead');
-       $admin->row_textarea(T('If you wish to set a template for entering the initial comment of a bug report, then you may specify this here. However, the template will only take effect on the initial report/comment. Note: the template cannot be forced on the user as there is no way to validate it.'), 'setting[defaultcomment]', $bugsys->options['defaultcomment']);
        
        $admin->table_end();
        
index ca9762ccd26a6e8e5d71b0c7c42f41b2f3844725..b2a0e40558eb6e4fa9fcbf69f1e59435fd839dc5 100644 (file)
@@ -37,5 +37,21 @@ class SettingsAction extends http\Action implements TemplatePreCaching
        {
                $response->data['title'] = T('Settings');
                $response->context['template'] = 'admin_settings';
+
+               // Save settings on POST.
+               if ($request->http_method == 'POST') {
+                       $query_bits = array();
+                       $values = array();
+                       foreach ($request->data['_POST']['settings'] AS $varname => $value) {
+                               $query_bits[] = '(?,?)';
+                               array_push($values, $varname, $value);
+                       }
+
+                       $query = bugdar::$db->Prepare("
+                               REPLACE into " . TABLE_PREFIX . "setting
+                                       (varname, value)
+                               VALUES " . implode(', ', $query_bits));
+                       $query->Execute($values);
+               }
        }
 }
index 661506f39c378084a57302b3049ca38cb25aa2ea..eb9bc69b079279f16f6c528507fc548244084f58 100644 (file)
@@ -1,5 +1,7 @@
 {%#import 'admin_header'%}
 
+<form method="post">
+
 <div ng-app="bugdar.admin.settings">
 
        <script type="text/ng-template" id="-/admin/settings/row.tpl">
                        <td ng-show="settingType == 'text'">
                                <input type="text" id="settings-{{name}}" name="settings[{{name}}]" value="{{value}}">
                        </td>
+
+                       <td ng-show="settingType == 'textarea'">
+                               <textarea id="settings-{{name}}" name="settings[{{name}}]">{{value}}</textarea>
+                       </td>
                </tr>
        </script>
 
                        title="{%=T('Use Header Redirects')%}"
                        description="{%=T('Instead of displaying an intermediate page informing the user that their action was a success and a redirect is occurring, just send the user to the next screen using HTTP headers. This can save bandwidth.')%}"
                        value="{%= Bugdar::$options['redirectheaders'] %}">
+               <tr setting-type="textarea"
+                       name="defaultcomment"
+                       title="{%=T('Default Comment Text')%}"
+                       description="{%=T('If you wish to set a template for entering the initial comment of a bug report, then you may specify this here. However, the template will only take effect on the initial report/comment. Note: the template cannot be forced on the user as there is no way to validate it.')%}">
+
+               <tr><th colspan="2"><input type="submit" value="Save Settings"></th></tr>
        </table>
 
 </div>
 
-{%#import 'admin_footer'%}
\ No newline at end of file
+</form>
+
+{%#import 'admin_footer'%}