From: Coleman Watts Date: Sat, 11 Jan 2014 19:14:30 +0000 (-0800) Subject: CRM-12872 - Search js - move search-only js out of Common.js X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=c1b06d1863c77e97027ae400cbea560403544440;p=civicrm-core.git CRM-12872 - Search js - move search-only js out of Common.js --- diff --git a/CRM/Activity/Form/Search.php b/CRM/Activity/Form/Search.php index fbd256f7b0..6f96900a3a 100644 --- a/CRM/Activity/Form/Search.php +++ b/CRM/Activity/Form/Search.php @@ -234,7 +234,7 @@ class CRM_Activity_Form_Search extends CRM_Core_Form { $rows = $this->get('rows'); if (is_array($rows)) { - CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js'); if (!$this->_single) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);") diff --git a/CRM/Campaign/Form/Search.php b/CRM/Campaign/Form/Search.php index eeb223a39c..03a60e5924 100755 --- a/CRM/Campaign/Form/Search.php +++ b/CRM/Campaign/Form/Search.php @@ -260,7 +260,7 @@ class CRM_Campaign_Form_Search extends CRM_Core_Form { $rows = $this->get('rows'); if (is_array($rows)) { - CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js'); if (!$this->_single) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")); foreach ($rows as $row) { diff --git a/CRM/Case/Form/Search.php b/CRM/Case/Form/Search.php index 6ef0848616..0c32579b83 100644 --- a/CRM/Case/Form/Search.php +++ b/CRM/Case/Form/Search.php @@ -244,7 +244,7 @@ class CRM_Case_Form_Search extends CRM_Core_Form { */ $rows = $this->get('rows'); if (is_array($rows)) { - CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js'); if (!$this->_single) { $this->addElement('checkbox', 'toggleSelect', diff --git a/CRM/Contact/Form/Search.php b/CRM/Contact/Form/Search.php index 6c0cf8e12c..1a137cfee2 100644 --- a/CRM/Contact/Form/Search.php +++ b/CRM/Contact/Form/Search.php @@ -372,7 +372,7 @@ class CRM_Contact_Form_Search extends CRM_Core_Form { */ function buildQuickForm() { CRM_Core_Resources::singleton() - ->addScriptFile('civicrm', 'js/crm.livePage.js') + ->addScriptFile('civicrm', 'js/crm.searchForm.js') // jsTree is needed for tags popup ->addScriptFile('civicrm', 'packages/jquery/plugins/jstree/jquery.jstree.js', 0, 'html-header', FALSE) ->addStyleFile('civicrm', 'packages/jquery/plugins/jstree/themes/default/style.css', 0, 'html-header'); diff --git a/CRM/Event/Form/Search.php b/CRM/Event/Form/Search.php index aa72ef59c4..5423afc77c 100644 --- a/CRM/Event/Form/Search.php +++ b/CRM/Event/Form/Search.php @@ -234,7 +234,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form { */ $rows = $this->get('rows'); if (is_array($rows)) { - CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js'); $lineItems = $eventIds = array(); if (!$this->_single) { $this->addElement('checkbox', diff --git a/CRM/Grant/Form/Search.php b/CRM/Grant/Form/Search.php index ae60d6ea9a..8399e8decf 100644 --- a/CRM/Grant/Form/Search.php +++ b/CRM/Grant/Form/Search.php @@ -228,7 +228,7 @@ class CRM_Grant_Form_Search extends CRM_Core_Form { $rows = $this->get('rows'); if (is_array($rows)) { - CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js'); if (!$this->_single) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onchange' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")); foreach ($rows as $row) { diff --git a/CRM/Member/Form/Search.php b/CRM/Member/Form/Search.php index 4dd4f5c728..4c575a4991 100644 --- a/CRM/Member/Form/Search.php +++ b/CRM/Member/Form/Search.php @@ -224,7 +224,7 @@ class CRM_Member_Form_Search extends CRM_Core_Form { $rows = $this->get('rows'); if (is_array($rows)) { - CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js'); if (!$this->_single) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")); foreach ($rows as $row) { diff --git a/CRM/Pledge/Form/Search.php b/CRM/Pledge/Form/Search.php index db82486008..c5df525e34 100644 --- a/CRM/Pledge/Form/Search.php +++ b/CRM/Pledge/Form/Search.php @@ -222,7 +222,7 @@ class CRM_Pledge_Form_Search extends CRM_Core_Form { */ $rows = $this->get('rows'); if (is_array($rows)) { - CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.livePage.js'); + CRM_Core_Resources::singleton()->addScriptFile('civicrm', 'js/crm.searchForm.js'); if (!$this->_single) { $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")); diff --git a/js/Common.js b/js/Common.js index 961495c216..31cdfcddb6 100644 --- a/js/Common.js +++ b/js/Common.js @@ -171,151 +171,6 @@ function showHideByValue(trigger_field_id, trigger_value, target_element_id, tar } } -/** - * - * Function for checking ALL or unchecking ALL check boxes in a resultset page. - * - * @access public - * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as - * belonging to the resultset's checkbox collection - * @param object - checkbox - * Sample usage: onClick="javascript:changeCheckboxValues('chk_', cj(this) );" - * - * @return - */ -function toggleCheckboxVals(fldPrefix, object) { - var val = (object.id == 'toggleSelect' && cj(object).is(':checked')); - cj('Input[id*="' + fldPrefix + '"],Input[id*="toggleSelect"]').prop('checked', val); - // change the class of selected rows - on_load_init_checkboxes(object.form.name); -} - -function countSelectedCheckboxes(fldPrefix, form) { - fieldCount = 0; - for (i = 0; i < form.elements.length; i++) { - fpLen = fldPrefix.length; - if (form.elements[i].type == 'checkbox' && form.elements[i].name.slice(0, fpLen) == fldPrefix && form.elements[i].checked == true) { - fieldCount++; - } - } - return fieldCount; -} - -/** - * Function to enable task action select - */ -function toggleTaskAction(status) { - var radio_ts = document.getElementsByName('radio_ts'); - if (!radio_ts[1]) { - radio_ts[0].checked = true; - } - if (radio_ts[0].checked || radio_ts[1].checked) { - status = true; - } - - var formElements = ['task', 'Go', 'Print']; - for (var i = 0; i < formElements.length; i++) { - var element = document.getElementById(formElements[i]); - if (element) { - if (status) { - element.disabled = false; - } - else { - element.disabled = true; - } - } - } -} - -/** - * This function is used to check if any actio is selected and also to check if any contacts are checked. - * - * @access public - * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as - * belonging to the resultset's checkbox collection - * @param form - name of form that checkboxes are part of - * Sample usage: onClick="javascript:checkPerformAction('chk_', myForm );" - * - */ -function checkPerformAction(fldPrefix, form, taskButton, selection) { - var cnt; - var gotTask = 0; - - // taskButton TRUE means we don't need to check the 'task' field - it's a button-driven task - if (taskButton == 1) { - gotTask = 1; - } - else { - if (document.forms[form].task.selectedIndex) { - //force user to select all search contacts, CRM-3711 - if (document.forms[form].task.value == 13 || document.forms[form].task.value == 14) { - var toggleSelect = document.getElementsByName('toggleSelect'); - if (toggleSelect[0].checked || document.forms[form].radio_ts[0].checked) { - return true; - } - else { - alert("Please select all contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button."); - return false; - } - } - gotTask = 1; - } - } - - if (gotTask == 1) { - // If user wants to perform action on ALL records and we have a task, return (no need to check further) - if (document.forms[form].radio_ts[0].checked) { - return true; - } - - cnt = (selection == 1) ? countSelections() : countSelectedCheckboxes(fldPrefix, document.forms[form]); - if (!cnt) { - alert("Please select one or more contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button."); - return false; - } - } - else { - alert("Please select an action from the drop-down menu."); - return false; - } -} - -/** - * This function changes the style for a checkbox block when it is selected. - * - * @access public - * @param chkName - it is name of the checkbox - * @return null - */ -function checkSelectedBox(chkName) { - var checkElement = cj('#' + chkName); - if (checkElement.prop('checked')) { - cj('input[value=ts_sel]:radio').prop('checked', true); - checkElement.parents('tr').addClass('crm-row-selected'); - } - else { - checkElement.parents('tr').removeClass('crm-row-selected'); - } -} - -/** - * This function is to show the row with selected checkbox in different color - * @param form - name of form that checkboxes are part of - * - * @access public - * @return null - */ -function on_load_init_checkboxes(form) { - var formName = form; - var fldPrefix = 'mark_x'; - for (i = 0; i < document.forms[formName].elements.length; i++) { - fpLen = fldPrefix.length; - if (document.forms[formName].elements[i].type == 'checkbox' && document.forms[formName].elements[i].name.slice(0, fpLen) == fldPrefix) { - checkSelectedBox(document.forms[formName].elements[i].name, formName); - } - } -} - /** * reset all the radio buttons with a given name * diff --git a/js/crm.searchForm.js b/js/crm.searchForm.js new file mode 100644 index 0000000000..86ccad87f5 --- /dev/null +++ b/js/crm.searchForm.js @@ -0,0 +1,168 @@ +// http://civicrm.org/licensing +// Controls search form action links and refreshes +cj(function($) { + $('#crm-main-content-wrapper') + // Widgetize the content area + .crmSnippet() + // Open action links in a popup + .off('click.crmLivePage') + .on('click.crmLivePage', 'a.button, a.action-item', function() { + var url = $(this).attr('href'); + // only follow real links not javascript buttons + if (url === '#' || $(this).attr('onclick') || $(this).hasClass('no-popup')) { + return; + } + CRM.loadForm(url, { + openInline: 'a:not("[href=#], .no-popup")' + }).on('crmFormSuccess', function(e, data) { + // Refresh page when form completes + $('#crm-main-content-wrapper').crmSnippet('refresh'); + }); + return false; + }); +}); + +/** + * + * Function for checking ALL or unchecking ALL check boxes in a resultset page. + * + * @access public + * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as + * belonging to the resultset's checkbox collection + * @param object - checkbox + * Sample usage: onClick="javascript:changeCheckboxValues('chk_', cj(this) );" + * + * @return + */ +function toggleCheckboxVals(fldPrefix, object) { + var val = (object.id == 'toggleSelect' && cj(object).is(':checked')); + cj('Input[id*="' + fldPrefix + '"],Input[id*="toggleSelect"]').prop('checked', val); + // change the class of selected rows + on_load_init_checkboxes(object.form.name); +} + +function countSelectedCheckboxes(fldPrefix, form) { + fieldCount = 0; + for (i = 0; i < form.elements.length; i++) { + fpLen = fldPrefix.length; + if (form.elements[i].type == 'checkbox' && form.elements[i].name.slice(0, fpLen) == fldPrefix && form.elements[i].checked == true) { + fieldCount++; + } + } + return fieldCount; +} + +/** + * This function changes the style for a checkbox block when it is selected. + * + * @access public + * @param chkName - it is name of the checkbox + * @return null + */ +function checkSelectedBox(chkName) { + var checkElement = cj('#' + chkName); + if (checkElement.prop('checked')) { + cj('input[value=ts_sel]:radio').prop('checked', true); + checkElement.parents('tr').addClass('crm-row-selected'); + } + else { + checkElement.parents('tr').removeClass('crm-row-selected'); + } +} + +/** + * This function is to show the row with selected checkbox in different color + * @param form - name of form that checkboxes are part of + * + * @access public + * @return null + */ +function on_load_init_checkboxes(form) { + var formName = form; + var fldPrefix = 'mark_x'; + for (i = 0; i < document.forms[formName].elements.length; i++) { + fpLen = fldPrefix.length; + if (document.forms[formName].elements[i].type == 'checkbox' && document.forms[formName].elements[i].name.slice(0, fpLen) == fldPrefix) { + checkSelectedBox(document.forms[formName].elements[i].name, formName); + } + } +} + +/** + * This function is used to check if any action is selected and also to check if any contacts are checked. + * + * @access public + * @param fldPrefix - common string which precedes unique checkbox ID and identifies field as + * belonging to the resultset's checkbox collection + * @param form - name of form that checkboxes are part of + * Sample usage: onClick="javascript:checkPerformAction('chk_', myForm );" + * + */ +function checkPerformAction(fldPrefix, form, taskButton, selection) { + var cnt; + var gotTask = 0; + + // taskButton TRUE means we don't need to check the 'task' field - it's a button-driven task + if (taskButton == 1) { + gotTask = 1; + } + else { + if (document.forms[form].task.selectedIndex) { + //force user to select all search contacts, CRM-3711 + if (document.forms[form].task.value == 13 || document.forms[form].task.value == 14) { + var toggleSelect = document.getElementsByName('toggleSelect'); + if (toggleSelect[0].checked || document.forms[form].radio_ts[0].checked) { + return true; + } + else { + alert("Please select all contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button."); + return false; + } + } + gotTask = 1; + } + } + + if (gotTask == 1) { + // If user wants to perform action on ALL records and we have a task, return (no need to check further) + if (document.forms[form].radio_ts[0].checked) { + return true; + } + + cnt = (selection == 1) ? countSelections() : countSelectedCheckboxes(fldPrefix, document.forms[form]); + if (!cnt) { + alert("Please select one or more contacts for this action.\n\nTo use the entire set of search results, click the 'all records' radio button."); + return false; + } + } + else { + alert("Please select an action from the drop-down menu."); + return false; + } +} + +/** + * Function to enable task action select + */ +function toggleTaskAction(status) { + var radio_ts = document.getElementsByName('radio_ts'); + if (!radio_ts[1]) { + radio_ts[0].checked = true; + } + if (radio_ts[0].checked || radio_ts[1].checked) { + status = true; + } + + var formElements = ['task', 'Go', 'Print']; + for (var i = 0; i < formElements.length; i++) { + var element = document.getElementById(formElements[i]); + if (element) { + if (status) { + element.disabled = false; + } + else { + element.disabled = true; + } + } + } +}