]> git.mxchange.org Git - quix0rs-gnu-social.git/commitdiff
Extended profile - make IMs display and save
authorZach Copley <zach@status.net>
Tue, 15 Mar 2011 05:38:34 +0000 (22:38 -0700)
committerZach Copley <zach@status.net>
Tue, 15 Mar 2011 05:38:34 +0000 (22:38 -0700)
plugins/ExtendedProfile/extendedprofile.php
plugins/ExtendedProfile/extendedprofilewidget.php
plugins/ExtendedProfile/js/profiledetail.js
plugins/ExtendedProfile/profiledetailsettingsaction.php

index 09d010b090bc86ae6dd7ff91d90f25d16ad45a43..6d78ddd3d89bb280ad33c89fbd6dfcef08a80c71 100644 (file)
@@ -129,6 +129,32 @@ class ExtendedProfile
         return $pArrays;
     }
 
+    function getIms()
+    {
+        $ims = (isset($this->fields['im'])) ? $this->fields['im'] : null;
+        $iArrays = array();
+
+        if (empty($ims)) {
+            $iArrays[] = array(
+                'label' => _m('IM'),
+                'type' => 'im'
+            );
+        } else {
+            for ($i = 0; $i < sizeof($ims); $i++) {
+                $ia = array(
+                    'label' => _m('IM'),
+                    'type'  => 'im',
+                    'index' => intval($ims[$i]->value_index),
+                    'rel'   => $ims[$i]->rel,
+                    'value' => $ims[$i]->field_value,
+                );
+
+                $iArrays[] = $ia;
+            }
+        }
+        return $iArrays;
+    }
+
     function getExperiences()
     {
         $companies = (isset($this->fields['company'])) ? $this->fields['company'] : null;
@@ -248,11 +274,7 @@ class ExtendedProfile
                 'label' => _m('Contact'),
                 'fields' => array(
                     'phone' => $this->getPhones(),
-                    'im' => array(
-                        'label' => _m('IM'),
-                        'type' => 'im',
-                        'multi' => true,
-                    ),
+                    'im' => $this->getIms(),
                     'website' => array(
                         'label' => _m('Websites'),
                         'type' => 'website',
index 03f70592fc7dfec691b374e9b468fb5f95460b67..5d5f1b7ab9a4fbf83ff3fad4316daea95b9fea74 100644 (file)
@@ -106,6 +106,7 @@ class ExtendedProfileWidget extends Form
 
             switch($fieldName) {
             case 'phone':
+            case 'im':
             case 'experience':
             case 'education':
                 $this->showMultiple($fieldName, $field);
@@ -156,6 +157,53 @@ class ExtendedProfileWidget extends Form
         $this->out->elementEnd('div');
     }
 
+    protected function showIm($name, $field)
+    {
+        $this->out->elementStart('div', array('class' => 'im-display'));
+        $this->out->text($field['value']);
+        if (!empty($field['rel'])) {
+            $this->out->text(' (' . $field['rel'] . ')');
+        }
+        $this->out->elementEnd('div');
+    }
+
+    protected function showEditableIm($name, $field)
+    {
+        $index = isset($field['index']) ? $field['index'] : 0;
+        $id    = "extprofile-$name-$index";
+        $rel   = $id . '-rel';
+        $this->out->elementStart(
+            'div', array(
+                'id' => $id . '-edit',
+                'class' => 'im-edit'
+            )
+        );
+        $this->out->input(
+            $id,
+            null,
+            isset($field['value']) ? $field['value'] : null
+        );
+        $this->out->dropdown(
+            $id . '-rel',
+            'Type',
+            array(
+                'jabber' => 'Jabber',
+                'gtalk'  => 'GTalk',
+                'aim'    => 'AIM',
+                'yahoo'  => 'Yahoo! Messenger',
+                'msn'    => 'MSN',
+                'skype'  => 'Skype',
+                'other'  => 'Other'
+            ),
+            null,
+            false,
+            isset($field['rel']) ? $field['rel'] : null
+        );
+
+        $this->showMultiControls();
+        $this->out->elementEnd('div');
+    }
+
     protected function showEditablePhone($name, $field)
     {
         $index = isset($field['index']) ? $field['index'] : 0;
@@ -373,6 +421,9 @@ class ExtendedProfileWidget extends Form
         case 'phone':
             $this->showPhone($name, $field);
             break;
+        case 'im':
+            $this->showIm($name, $field);
+            break;
         case 'experience':
             $this->showExperience($name, $field);
             break;
@@ -413,6 +464,9 @@ class ExtendedProfileWidget extends Form
         case 'phone':
             $this->showEditablePhone($name, $field);
             break;
+        case 'im':
+            $this->showEditableIm($name, $field);
+            break;
         case 'experience':
             $this->showEditableExperience($name, $field);
             break;
index d491b46ba65c92500f94268ddc6ea5283a70967d..cdd7467e934b506d44f39155cf7808f846e74529 100644 (file)
@@ -84,6 +84,7 @@ var init = function() {
     reorder('phone-edit');
     reorder('experience-edit');
     reorder('education-edit');
+    reorder('im-edit');
 }
 
 $(document).ready(
index 3708f54d65027ab14fdb9930b53a831e900b6ef5..baac80a482d9ff335abe438d9f83c76081f33079 100644 (file)
@@ -109,6 +109,7 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
             }
 
             $this->savePhoneNumbers($user);
+            $this->saveIms($user);
             $this->saveExperiences($user);
             $this->saveEducations($user);
 
@@ -159,6 +160,44 @@ class ProfileDetailSettingsAction extends ProfileSettingsAction
         return $phoneArray;
     }
 
+    function findIms() {
+
+        //  Form vals look like this:
+        // 'extprofile-im-0' => 'jed',
+        // 'extprofile-im-0-rel' => 'yahoo',
+
+        $ims     = $this->sliceParams('im', 2);
+        $imArray = array();
+
+        foreach ($ims as $im) {
+            list($id, $rel) = array_values($im);
+            $imArray[] = array(
+                'value' => $id,
+                'rel'   => $rel
+            );
+        }
+
+        return $imArray;
+    }
+
+    function saveIms($user) {
+        $ims = $this->findIms();
+        $this->removeAll($user, 'im');
+        $i = 0;
+        foreach($ims as $im) {
+            if (!empty($im['value'])) {
+                ++$i;
+                $this->saveField(
+                    $user,
+                    'im',
+                    $im['value'],
+                    $im['rel'],
+                    $i
+                );
+            }
+        }
+    }
+
     function findExperiences() {
 
         // Form vals look like this: