Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | {* |
2 | +--------------------------------------------------------------------+ | |
819d0d41 | 3 | | CiviCRM version 4.5 | |
6a488035 | 4 | +--------------------------------------------------------------------+ |
819d0d41 | 5 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
6 | +--------------------------------------------------------------------+ |
7 | | This file is a part of CiviCRM. | | |
8 | | | | |
9 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
10 | | under the terms of the GNU Affero General Public License | | |
11 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
12 | | | | |
13 | | CiviCRM is distributed in the hope that it will be useful, but | | |
14 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
16 | | See the GNU Affero General Public License for more details. | | |
17 | | | | |
18 | | You should have received a copy of the GNU Affero General Public | | |
19 | | License and the CiviCRM Licensing Exception along | | |
20 | | with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | *} | |
26 | {* This included tpl checks if a given username is taken or available. *} | |
27 | {literal} | |
28 | var lastName = null; | |
29 | cj("#checkavailability").click(function() { | |
30 | var cmsUserName = cj.trim(cj("#cms_name").val()); | |
31 | if ( lastName == cmsUserName) { | |
32 | /*if user checking the same user name more than one times. avoid the ajax call*/ | |
33 | return; | |
34 | } | |
35 | /*don't allow special character and for joomla minimum username length is two*/ | |
36 | ||
37 | var spchar = "\<|\>|\"|\'|\%|\;|\(|\)|\&|\\\\|\/"; | |
38 | ||
39 | {/literal}{if $config->userSystem->is_drupal == "1"}{literal} | |
40 | spchar = spchar + "|\~|\`|\:|\@|\!|\=|\#|\$|\^|\*|\{|\}|\\[|\\]|\+|\?|\,"; | |
41 | {/literal}{/if}{literal} | |
42 | var r = new RegExp( "["+spchar+"]", "i"); | |
43 | /*regular expression \\ matches a single backslash. this becomes r = /\\/ or r = new RegExp("\\\\").*/ | |
44 | if ( r.exec(cmsUserName) ) { | |
45 | alert('{/literal}{ts escape="js"}Your username contains invalid characters{/ts}{literal}'); | |
46 | return; | |
47 | } | |
48 | {/literal}{if $config->userFramework == "Joomla"}{literal} | |
49 | else if ( cmsUserName && cmsUserName.length < 2 ) { | |
50 | alert('{/literal}{ts escape="js"}Your username is too short{/ts}{literal}'); | |
51 | return; | |
52 | } | |
53 | {/literal}{/if}{literal} | |
54 | if (cmsUserName) { | |
55 | /*take all messages in javascript variable*/ | |
56 | var check = "{/literal}{ts escape='js'}Checking...{/ts}{literal}"; | |
57 | var available = "{/literal}{ts escape='js'}This username is currently available.{/ts}{literal}"; | |
58 | var notavailable = "{/literal}{ts escape='js'}This username is taken.{/ts}{literal}"; | |
59 | ||
60 | //remove all the class add the messagebox classes and start fading | |
61 | cj("#msgbox").removeClass().addClass('cmsmessagebox').css({"color":"#000","backgroundColor":"#FFC","border":"1px solid #c93"}).text(check).fadeIn("slow"); | |
62 | ||
63 | //check the username exists or not from ajax | |
64 | var contactUrl = {/literal}"{crmURL p='civicrm/ajax/cmsuser' h=0 }"{literal}; | |
65 | ||
66 | cj.post(contactUrl,{ cms_name:cj("#cms_name").val() } ,function(data) { | |
67 | if ( data.name == "no") {/*if username not avaiable*/ | |
68 | cj("#msgbox").fadeTo(200,0.1,function() { | |
69 | cj(this).html(notavailable).addClass('cmsmessagebox').css({"color":"#CC0000","backgroundColor":"#F7CBCA","border":"1px solid #CC0000"}).fadeTo(900,1); | |
70 | }); | |
71 | } else { | |
72 | cj("#msgbox").fadeTo(200,0.1,function() { | |
73 | cj(this).html(available).addClass('cmsmessagebox').css({"color":"#008000","backgroundColor":"#C9FFCA", "border": "1px solid #349534"}).fadeTo(900,1); | |
74 | }); | |
75 | } | |
76 | }, "json"); | |
77 | lastName = cmsUserName; | |
78 | } else { | |
79 | cj("#msgbox").removeClass().text('').css({"backgroundColor":"#FFFFFF", "border": "0px #FFFFFF"}).fadeIn("fast"); | |
80 | } | |
81 | }); | |
82 | {/literal} |