Hi Paul,
This is an interesting situation and as of today there is no easy, upgrade safe customization that I am seeing in the product to support this. With that said, I do think something like having role permission to enable/disable hide/show editable fields would be a nice feature to add in a future release of the produce.
From what I can see (and I'm sure there may be tweaks needed as I haven't had too much time to look into it in depth) here is a quick solution.
1) Modify include/SugarEmailAddress/templates/forEditView.tpl
This is the file that renders the edit view's widgets.
What I would do to this file is:
Around line 53 where there is this block of code:
Code:
{if $useOptOut == true}
<td scope="row" NOWRAP>
{$app_strings.LBL_EMAIL_OPT_OUT}
</td>
{/if} I wouid take out the if checks and change it to:
Code:
<td scope="row" NOWRAP>
{$app_strings.LBL_EMAIL_OPT_OUT}
</td>
Around line 70 or so I'd add ids to the image and href fields
So change
Code:
<a href="javascript:addEmailAddress({literal}'{/literal}{$module}emailAddressesTable{literal}'{/literal},'','');"><img src="themes/Sugar/images/plus_inline.gif" border="0" height="10" width="10" class="img"></a>
<a href="javascript:addEmailAddress({literal}'{/literal}{$module}emailAddressesTable{literal}'{/literal},'','');">{$app_strings.LBL_EMAIL_ADD}</a>
to
Code:
<a id="add_email_icon" href="javascript:addEmailAddress({literal}'{/literal}{$module}emailAddressesTable{literal}'{/literal},'','');"><img src="themes/Sugar/images/plus_inline.gif" border="0" height="10" width="10" class="img"></a>
<a id="add_email_link" href="javascript:addEmailAddress({literal}'{/literal}{$module}emailAddressesTable{literal}'{/literal},'','');">{$app_strings.LBL_EMAIL_ADD}</a>
Then at the end of this file I would add this entire block of code:
Code:
{if !$useOptOut}
{literal}
<script type="text/javascript" language="javascript">
function set_opt_out_fields() {
var els = document.getElementsByTagName("input");
for(x in els) {
if(els[x].type && els[x].type == 'checkbox' && /^emailAddressOptOut/.test(els[x].id)) {
els[x].disabled = true;
}
}
}
function initialize() {
document.getElementById("add_email_icon").removeAttribute("href");
document.getElementById("add_email_link").removeAttribute("href");
document.getElementById("add_email_icon").setAttribute("onclick", "addEmailAddress('{/literal}{$module}emailAddressesTable{literal}','',''); set_opt_out_fields();");
document.getElementById("add_email_link").setAttribute("onclick", "addEmailAddress('{/literal}{$module}emailAddressesTable{literal}','',''); set_opt_out_fields();");
set_opt_out_fields();
}
YAHOO.util.Event.onDOMReady(initialize);
</script>
{/literal}
{/if}
2) Then I would modify include/SugarEmailAddress/SugarEmailAddress.php
Change this block of code:
Code:
$this->smarty->assign('useOptOut', true);
to
Code:
$this->smarty->assign('useOptOut', $GLOBALS['current_user']->is_admin || $GLOBALS['current_user']->check_role_membership('Marketing Administrator Role'));
Summary
What I am doing here is using some javascript to disbale the checkbox fields if the user is not an admin or is not in the "Marketing Administrator Role". I just chose that as an example.
Notes
* Only tested this on Firefox
* If YAHOO.util.Event.onDOMReady is not available for your version of Sugar then I'd scan other .js (javascript) files to find which on ready function to use (it may be Ext instead)
* Example disable fields, but you could also code around it to remove it (set checkbox visibility to hidden, etc.) up to you...
Best wishes!
Bookmarks