]> git.mxchange.org Git - quix0rs-gnu-social.git/blobdiff - lib/applicationeditform.php
Merge branch 'testing' of git@gitorious.org:statusnet/mainline into 0.9.x
[quix0rs-gnu-social.git] / lib / applicationeditform.php
index 3fd45876a728cf1766a42fbbd636103244135619..9b7d0586143304586ab3f103262c4e08766b4e63 100644 (file)
@@ -81,6 +81,21 @@ class ApplicationEditForm extends Form
         }
     }
 
+    /**
+     * HTTP method used to submit the form
+     *
+     * For image data we need to send multipart/form-data
+     * so we set that here too
+     *
+     * @return string the method to use for submitting
+     */
+
+    function method()
+    {
+        $this->enctype = 'multipart/form-data';
+        return 'post';
+    }
+
     /**
      * class of the form
      *
@@ -100,7 +115,9 @@ class ApplicationEditForm extends Form
 
     function action()
     {
-        if ($this->application) {
+        $cur = common_current_user();
+
+        if (!empty($this->application)) {
             return common_local_url('editapplication',
                                     array('id' => $this->application->id));
         } else {
@@ -116,7 +133,7 @@ class ApplicationEditForm extends Form
 
     function formLegend()
     {
-        $this->out->element('legend', null, _('Register a new application'));
+        $this->out->element('legend', null, _('Edit application'));
     }
 
     /**
@@ -129,8 +146,9 @@ class ApplicationEditForm extends Form
     {
         if ($this->application) {
             $id                = $this->application->id;
+            $icon              = $this->application->icon;
             $name              = $this->application->name;
-            $description       = $this->application->description; 
+            $description       = $this->application->description;
             $source_url        = $this->application->source_url;
             $organization      = $this->application->organization;
             $homepage          = $this->application->homepage;
@@ -139,6 +157,7 @@ class ApplicationEditForm extends Form
             $this->access_type = $this->application->access_type;
         } else {
             $id                = '';
+            $icon              = '';
             $name              = '';
             $description       = '';
             $source_url        = '';
@@ -150,35 +169,65 @@ class ApplicationEditForm extends Form
         }
 
         $this->out->elementStart('ul', 'form_data');
+
+        $this->out->elementStart('li', array('id' => 'application_icon'));
+
+        if (!empty($icon)) {
+            $this->out->element('img', array('src' => $icon));
+        }
+
+        $this->out->element('label', array('for' => 'app_icon'),
+                            _('Icon'));
+        $this->out->element('input', array('name' => 'app_icon',
+                                           'type' => 'file',
+                                           'id' => 'app_icon'));
+        $this->out->element('p', 'form_guide', _('Icon for this application'));
+        $this->out->element('input', array('name' => 'MAX_FILE_SIZE',
+                                           'type' => 'hidden',
+                                           'id' => 'MAX_FILE_SIZE',
+                                           'value' => ImageFile::maxFileSizeInt()));
+        $this->out->elementEnd('li');
+
         $this->out->elementStart('li');
-        
+
         $this->out->hidden('application_id', $id);
+
         $this->out->input('name', _('Name'),
                           ($this->out->arg('name')) ? $this->out->arg('name') : $name);
-                    
+
         $this->out->elementEnd('li');
-        
+
         $this->out->elementStart('li');
-        $this->out->input('description', _('Description'),
-                          ($this->out->arg('Description')) ? $this->out->arg('discription') : $description);
+
+        $maxDesc = Oauth_application::maxDesc();
+        if ($maxDesc > 0) {
+            $descInstr = sprintf(_('Describe your application in %d characters'),
+                                 $maxDesc);
+        } else {
+            $descInstr = _('Describe your application');
+        }
+        $this->out->textarea('description', _('Description'),
+                        ($this->out->arg('description')) ? $this->out->arg('description') : $description,
+                             $descInstr);
+
         $this->out->elementEnd('li');
-        
+
         $this->out->elementStart('li');
         $this->out->input('source_url', _('Source URL'),
                           ($this->out->arg('source_url')) ? $this->out->arg('source_url') : $source_url,
                           _('URL of the homepage of this application'));
-        $this->out->elementEnd('li');        
+        $this->out->elementEnd('li');
 
         $this->out->elementStart('li');
-        $this->out->input('Organization', _('Organization'),
-                          ($this->out->arg('organization')) ? $this->out->arg('organization') : $orgranization,
+        $this->out->input('organization', _('Organization'),
+                          ($this->out->arg('organization')) ? $this->out->arg('organization') : $organization,
                           _('Organization responsible for this application'));
         $this->out->elementEnd('li');
 
         $this->out->elementStart('li');
         $this->out->input('homepage', _('Homepage'),
                           ($this->out->arg('homepage')) ? $this->out->arg('homepage') : $homepage,
-                          _('URL of the homepage of the organization'));
+                          _('URL for the homepage of the organization'));
         $this->out->elementEnd('li');
 
         $this->out->elementStart('li');
@@ -187,18 +236,87 @@ class ApplicationEditForm extends Form
                           _('URL to redirect to after authentication'));
         $this->out->elementEnd('li');
 
-        $this->out->elementStart('li');
-        $this->out->input('type', _('Application type'),
-                          ($this->out->arg('type')) ? $this->out->arg('type') : $type,
-                          _('Type of application, browser or desktop'));
+        $this->out->elementStart('li', array('id' => 'application_types'));
+
+        $attrs = array('name' => 'app_type',
+                       'type' => 'radio',
+                       'id' => 'app_type-browser',
+                       'class' => 'radio',
+                       'value' => Oauth_application::$browser);
+
+        // Default to Browser
+
+        if ($this->application->type == Oauth_application::$browser
+            || empty($this->application->type)) {
+            $attrs['checked'] = 'checked';
+        }
+
+        $this->out->element('input', $attrs);
+
+        $this->out->element('label', array('for' => 'app_type-browser',
+                                           'class' => 'radio'),
+                            _('Browser'));
+
+        $attrs = array('name' => 'app_type',
+                       'type' => 'radio',
+                       'id' => 'app_type-dekstop',
+                       'class' => 'radio',
+                       'value' => Oauth_application::$desktop);
+
+        if ($this->application->type == Oauth_application::$desktop) {
+            $attrs['checked'] = 'checked';
+        }
+
+        $this->out->element('input', $attrs);
+
+        $this->out->element('label', array('for' => 'app_type-desktop',
+                                           'class' => 'radio'),
+                            _('Desktop'));
+        $this->out->element('p', 'form_guide', _('Type of application, browser or desktop'));
         $this->out->elementEnd('li');
-        
-        $this->out->elementStart('li');
-        $this->out->input('access_type', _('Default access'),
-                          ($this->out->arg('access_type')) ? $this->out->arg('access_type') : $access_type,
-                          _('Default access for this application: read-write, or read-only'));
+
+        $this->out->elementStart('li', array('id' => 'default_access_types'));
+
+        $attrs = array('name' => 'default_access_type',
+                       'type' => 'radio',
+                       'id' => 'default_access_type-r',
+                       'class' => 'radio',
+                       'value' => 'r');
+
+        // default to read-only access
+
+        if ($this->application->access_type & Oauth_application::$readAccess
+            || empty($this->application->access_type)) {
+            $attrs['checked'] = 'checked';
+        }
+
+        $this->out->element('input', $attrs);
+
+        $this->out->element('label', array('for' => 'default_access_type-ro',
+                                           'class' => 'radio'),
+                            _('Read-only'));
+
+        $attrs = array('name' => 'default_access_type',
+                       'type' => 'radio',
+                       'id' => 'default_access_type-rw',
+                       'class' => 'radio',
+                       'value' => 'rw');
+
+        if ($this->application->access_type & Oauth_application::$readAccess
+            && $this->application->access_type & Oauth_application::$writeAccess
+            ) {
+            $attrs['checked'] = 'checked';
+        }
+
+        $this->out->element('input', $attrs);
+
+        $this->out->element('label', array('for' => 'default_access_type-rw',
+                                           'class' => 'radio'),
+                            _('Read-write'));
+        $this->out->element('p', 'form_guide', _('Default access for this application: read-only, or read-write'));
+
         $this->out->elementEnd('li');
-        
+
         $this->out->elementEnd('ul');
     }
 
@@ -210,6 +328,9 @@ class ApplicationEditForm extends Form
 
     function formActions()
     {
-        $this->out->submit('submit', _('Save'));
+        $this->out->submit('cancel', _('Cancel'), 'submit form_action-primary',
+                           'cancel', _('Cancel'));
+        $this->out->submit('save', _('Save'), 'submit form_action-secondary',
+                           'save', _('Save'));
     }
 }