From 7c2a9310c4104f51fcf56379dcc3511fa5bfae2d Mon Sep 17 00:00:00 2001
From: thomascube <thomas@roundcube.net>
Date: Mon, 02 Jan 2012 09:44:28 -0500
Subject: [PATCH] Use iframes for identity management

---
 program/steps/settings/identities.inc    |    2 
 program/localization/en_US/messages.inc  |    1 
 program/steps/settings/save_identity.inc |   13 +++++-
 skins/larry/templates/identities.html    |    7 ++-
 program/js/app.js                        |   32 ++++++++++++++--
 program/steps/settings/edit_identity.inc |    1 
 skins/larry/templates/identityedit.html  |   36 +++---------------
 skins/larry/ui.js                        |    2 
 8 files changed, 53 insertions(+), 41 deletions(-)

diff --git a/program/js/app.js b/program/js/app.js
index be6ca8d..27af1ff 100644
--- a/program/js/app.js
+++ b/program/js/app.js
@@ -351,11 +351,18 @@
         this.enable_command('preferences', 'identities', 'save', 'folders', true);
 
         if (this.env.action == 'identities') {
-          this.enable_command('add', this.env.identities_level < 2);
+          this.enable_command('add', 'delete', this.env.identities_level < 2);
         }
         else if (this.env.action == 'edit-identity' || this.env.action == 'add-identity') {
           this.enable_command('add', this.env.identities_level < 2);
-          this.enable_command('save', 'delete', 'edit', 'toggle-editor', true);
+          this.enable_command('save', 'edit', 'toggle-editor', true);
+          if (this.is_framed() && this.env.identities_level < 2)
+            this.set_button('delete', 'act');  // activate button but delegate command to parent
+          else
+            this.enable_command('delete', this.env.identities_level < 2);
+
+          if (this.env.action == 'add-identity')
+            $("input[type='text']").first().select();
         }
         else if (this.env.action == 'folders') {
           this.enable_command('subscribe', 'unsubscribe', 'create-folder', 'rename-folder', true);
@@ -4770,11 +4777,28 @@
     if (!id)
       id = this.env.iid ? this.env.iid : selection[0];
 
-    // append token to request
-    this.goto_url('delete-identity', '_iid='+id+'&_token='+this.env.request_token, true);
+    // submit request with appended token
+    if (confirm(this.get_label('deleteidentityconfirm')))
+      this.goto_url('delete-identity', '_iid='+id+'&_token='+this.env.request_token, true);
 
     return true;
   };
+  
+  this.update_identity_row = function(id, name, add)
+  {
+    var row, col, list = this.identity_list,
+      rid = this.html_identifier(id);
+
+    if (list.rows[rid] && (row = list.rows[rid].obj)) {
+      $(row.cells[0]).html(name);
+    }
+    else if (add) {
+      row = $('<tr>').attr('id', 'rcmrow'+rid).get(0);
+      col = $('<td>').addClass('mail').html(name).appendTo(row);
+      list.insert_row(row);
+      list.select(rid);
+    }
+  };
 
 
   /*********************************************************/
diff --git a/program/localization/en_US/messages.inc b/program/localization/en_US/messages.inc
index aae086e..525df95 100644
--- a/program/localization/en_US/messages.inc
+++ b/program/localization/en_US/messages.inc
@@ -109,6 +109,7 @@
 $messages['removingmember'] = 'Removing contact(s) from the group...';
 $messages['receiptsent'] = 'Successfully sent a read receipt.';
 $messages['errorsendingreceipt'] = 'Could not send the receipt.';
+$messages['deleteidentityconfirm'] = 'Do you really want to delete this identity?';
 $messages['nodeletelastidentity'] = 'You cannot delete this identity, it\'s your last one.';
 $messages['forbiddencharacter'] = 'Folder name contains a forbidden character.';
 $messages['selectimportfile'] = 'Please select a file to upload.';
diff --git a/program/steps/settings/edit_identity.inc b/program/steps/settings/edit_identity.inc
index f0c4776..188d107 100644
--- a/program/steps/settings/edit_identity.inc
+++ b/program/steps/settings/edit_identity.inc
@@ -151,6 +151,7 @@
 $OUTPUT->include_script('list.js');
 $OUTPUT->add_handler('identityform', 'rcube_identity_form');
 $OUTPUT->set_env('identities_level', IDENTITIES_LEVEL);
+$OUTPUT->add_label('deleteidentityconfirm');
 
 $OUTPUT->set_pagetitle(rcube_label(($RCMAIL->action=='add-identity' ? 'newidentity' : 'edititem')));
 
diff --git a/program/steps/settings/identities.inc b/program/steps/settings/identities.inc
index 6fc2cc1..95ff31a 100644
--- a/program/steps/settings/identities.inc
+++ b/program/steps/settings/identities.inc
@@ -22,7 +22,6 @@
 define('IDENTITIES_LEVEL', intval($RCMAIL->config->get('identities_level', 0)));
 
 $OUTPUT->set_pagetitle(rcube_label('identities'));
-
 $OUTPUT->include_script('list.js');
 
 
@@ -43,5 +42,6 @@
 
 $OUTPUT->add_handler('identityframe', 'rcmail_identity_frame');
 $OUTPUT->set_env('identities_level', IDENTITIES_LEVEL);
+$OUTPUT->add_label('deleteidentityconfirm');
 
 $OUTPUT->send('identities');
diff --git a/program/steps/settings/save_identity.inc b/program/steps/settings/save_identity.inc
index f88e732..0a06b42 100644
--- a/program/steps/settings/save_identity.inc
+++ b/program/steps/settings/save_identity.inc
@@ -96,7 +96,7 @@
 
     if ($_POST['_framed']) {
       // update the changed col in list
-      // ...
+      $OUTPUT->command('parent.update_identity_row', $iid, Q(trim($save_data['name'] . ' <' . rcube_idn_to_utf8($save_data['email']) .'>')));
     }
   }
   else {
@@ -135,6 +135,11 @@
 
     if (!empty($_POST['_standard']))
       $default_id = $insert_id;
+
+    if ($_POST['_framed']) {
+      // add a new row to the list
+      $OUTPUT->command('parent.update_identity_row', $insert_id, Q(trim($save_data['name'] . ' <' . rcube_idn_to_utf8($save_data['email']) .'>')), true);
+    }
   }
   else {
     // show error message
@@ -152,4 +157,8 @@
   $RCMAIL->user->set_default($default_id);
 
 // go to next step
-rcmail_overwrite_action('identities');
+if (!empty($_REQUEST['_framed'])) {
+  rcmail_overwrite_action('edit-identity');
+}
+else
+  rcmail_overwrite_action('identities');
diff --git a/skins/larry/templates/identities.html b/skins/larry/templates/identities.html
index 905bc10..a488218 100644
--- a/skins/larry/templates/identities.html
+++ b/skins/larry/templates/identities.html
@@ -20,12 +20,13 @@
 <roundcube:object name="identitiesList" id="identities-table" class="listing" cellspacing="0" summary="Identities list" noheader="true" editIcon="" />
 </div>
 <div class="boxfooter">
-<roundcube:button command="add" type="link" title="newidentity" class="listbutton add disabled" classAct="listbutton add" innerClass="inner" content="+" condition="config:identities_level:0<2" />
+<roundcube:button command="add" type="link" title="newidentity" class="listbutton add disabled" classAct="listbutton add" innerClass="inner" content="+" condition="config:identities_level:0<2" /><roundcube:button command="delete" type="link" title="delete" class="listbutton delete disabled" classAct="listbutton delete" innerClass="inner" content="-" condition="config:identities_level:0<2" />
 </div>
 </div>
 
-<div id="identity-details" class="uibox contentbox watermark">
-<roundcube:object name="message" id="message" class="statusbar" />
+<div id="identity-details" class="uibox contentbox">
+	<roundcube:object name="identityframe" id="preferences-frame" style="width:100%; height:96%" src="/watermark.html" />
+	<roundcube:object name="message" id="message" class="statusbar" />
 </div>
 
 </div>
diff --git a/skins/larry/templates/identityedit.html b/skins/larry/templates/identityedit.html
index d31c4a6..2657c2d 100644
--- a/skins/larry/templates/identityedit.html
+++ b/skins/larry/templates/identityedit.html
@@ -4,43 +4,19 @@
 <title><roundcube:object name="pagetitle" /></title>
 <roundcube:include file="/includes/links.html" />
 </head>
-<body>
+<body class="iframe">
 
-<roundcube:include file="/includes/header.html" />
-
-<div id="mainscreen" class="offset">
-
-<roundcube:include file="/includes/settingstabs.html" />
-
-<div id="settings-right">
-
-<div id="identitieslist" class="uibox listbox">
-<h2 class="boxtitle"><roundcube:label name="identities" /></h2>
-<div class="scroller withfooter">
-<roundcube:object name="identitiesList" id="identities-table" class="listing" noheader="true" editIcon="" />
-</div>
-<div class="boxfooter">
-<roundcube:button command="add" type="link" title="newidentity" class="listbutton add disabled" classAct="listbutton add" innerClass="inner" content="+" condition="config:identities_level:0<2" />
-</div>
-</div>
-
-<div id="identity-details" class="uibox contentbox">
 <h1 class="boxtitle"><roundcube:object name="steptitle" /></h1>
 
-<div class="boxcontent scroller">
+<div id="preferences-details" class="boxcontent">
 <roundcube:object name="identityform" class="propform" size="40" textareacols="40" textarearows="6" />
+</div>
 
-<p class="formbuttons">
+<div id="formfooter">
+<div class="footerleft formbuttons">
 	<roundcube:button command="save" type="input" class="button mainaction" label="save" />
-	<roundcube:button command="delete" type="input" class="button" label="delete" condition="env:action=='edit-identity'" />
-</p>
+	<roundcube:button command="delete" type="input" class="button" label="delete" condition="env:action=='edit-identity' && config:identities_level:0<2" />
 </div>
-
-<roundcube:object name="message" id="message" class="statusbar" />
-</div>
-
-</div>
-
 </div>
 
 <roundcube:include file="/includes/footer.html" />
diff --git a/skins/larry/ui.js b/skins/larry/ui.js
index 6729fa6..c43198a 100644
--- a/skins/larry/ui.js
+++ b/skins/larry/ui.js
@@ -120,7 +120,7 @@
         new rcube_splitter({ id:'folderviewsplitter', p1:'#folderslist', p2:'#folder-details',
           orientation:'v', relative:true, start:305, min:150, size:12 }).init();
       }
-      else if (rcmail.env.action.indexOf('identit') >= 0) {
+      else if (rcmail.env.action == 'identities') {
         new rcube_splitter({ id:'identviewsplitter', p1:'#identitieslist', p2:'#identity-details',
           orientation:'v', relative:true, start:305, min:150, size:12 }).init();
       }

--
Gitblit v1.9.1