Friday, November 11, 2016

SharePoint 2013 Customize Task Form



<script language="javascript">
                            function isEqual(str1, str2, doExactMatch)
                            {
                            var result = false;
                            try
                            {
                            if (doExactMatch == true)
                            {
                            result = (str1.trim().toLowerCase() == str2.trim().toLowerCase());
                            }
                            else
                            {
                            result = (str1.trim().toLowerCase().indexOf(str2.trim().toLowerCase()) >= 0);
                            }
                            }catch(err){result = false;}
                            return result;
                            }
                            function getFormRowByCaption(tbl, cap, formCaptionIndex, doHide, doExactMatch)
                            {
                            var result = null;
                            try
                            {
                            console.log('getFormRowByCaption() -> START');
                            if (tbl.id != null)
                            console.log('getFormRowByCaption() -> tbl ID-> ' + tbl.id);
                            else
                            console.log('getFormRowByCaption() -> tbl ID-> ' + tbl[0].outerHTML.trim().substring(0,20));
                            //console.log('getFormRowByCaption() -> tbl .exists()-> ' + tbl.exists());
                            console.log('getFormRowByCaption() -> tbl length-> ' + tbl.length);;

                            //$('tr').each(function()
                            tbl.find('tbody tr').each(function()
                            {
                            var atd = $(this).find('td').eq(formCaptionIndex);
                            var isMatch = false;
                            try
                            {
                            console.log('getFormRowByCaption() -> atd.Text()-> ' + atd.text().trim());
                            //(atd.text().trim().toLowerCase().indexOf(cap) >= 0);
                            isMatch = isEqual(atd.text(), cap, doExactMatch);
                            }
                            catch(err){isMatch = false;}
                            try{if (isMatch == false) isMatch = isEqual(atd[0].innerText, cap, doExactMatch);}
                            catch(err){isMatch = false;}
                            try{if (isMatch == false) isMatch = isEqual(atd[0].innerHTML, cap, doExactMatch);}
                            catch(err){isMatch = false;}

                            if ( isMatch==true )
                            {
                            result = atd.closest("tr");
                            try{
                            console.log('getFormRowByCaption() -> FOUND ROW!');
                            console.log('getFormRowByCaption() -> RESULT-> '
                            + result[0].outerHTML.trim().substring(0,50));
                            }
                            catch(err){}
                            if (doHide == true)
                            result.hide();
                            return false;
                            }
                            });
                            console.log('getFormRowByCaption() -> DONE');
                            }
                            catch(err){}
                            return result;
                            }
                            $(document).ready(function() {
                            try
                            {
                            /*****************************************
                            // Task 241
                            task Form Shall show in order:
                            1. Display:  Task Name
                            2. Display:  Task Due Date
                            3. Data entry: Change Assigned To.  (not necessary, but the users like it)
                            4. Add comments field.
                            5. Data entry: Enter a Reject Reason (if applicable to task).
                            5. Allow Comments
                            ******************************************/
                            /*****************************************
                            // Task 86 Change Field Title from Choose Purchase Order Document to  Choose SA Purchase Order
                            ******************************************/
                            if (document.URL.indexOf('LeasingLeasingDealPipeline/EditTM.aspx') || document.URL.indexOf('LeasingLeasingDealPipeline/EditDeal.aspx'))
                            {
                            var ftr = getFormRowByCaption($('table.deal-UI-table:first')  , 'Choose Purchase Order Document', 0, false, false);
                            if (ftr) ftr.find("td:first>.ms-standardheader").text('Choose SA Purchase Order');

                            }
                            if (document.URL.indexOf('Leasing/WorkflowTasks/EditForm.aspx') && $('[id*=SaveItem]') != null && document.URL.indexOf('/WorkflowTasks/') > 0 )
                            {
                            /*****************************************
                            // Task 52 Save Button Hide
                            // Workflow Task Save Button Hide All Forms in lieu of Form Content Type mods abc
                            ******************************************/
                            // save button
                            if ($('[id*=ContentTypeChoice] option:selected') != null)
                            {
                            var contenttype = $('[id*=ContentTypeChoice] option:selected').text().toLowerCase();
                            if ((contenttype == "request ls rlm approval" || contenttype == "request rsm approval" || contenttype == "request new collo app") || (/^sa/).test('sa'))
                            $('[id*=SaveItem]').css('display', 'none');
                            }
                            //   return;
                            // TASK
                            // problem task outcome
                            //http://stageportal.verticalbridge.com/Leasing/WorkflowTasks/EditForm.aspx?ID=3121&Source=http%3A%2F%2Fstageportal%2Everticalbridge%2Ecom%2FLeasing%2FPages%2FDealDashboard%2Easpx%3FDealNo%3DD-001423

                            var tbl = $('table.ms-formtable:first');
                            // content type
                            getFormRowByCaption(tbl , 'content', 0, true, false);
                            //start date
                            getFormRowByCaption(tbl , 'start date', 0, true, true);
                            //pct conplete
                            getFormRowByCaption(tbl , '% complete', 0, true, true);
                            //priority
                            getFormRowByCaption(tbl , 'priority', 0, true, true);
                            //status
                            getFormRowByCaption(tbl , 'status', 0, true, true);
                            //deal num
                            getFormRowByCaption(tbl , 'deal number', 0, true, true);
                            // Misc cls that may appear
                            //Related Items
                            getFormRowByCaption(tbl , 'Related Items', 0, true, false);
                            //RequestNewColloApp
                            //   debugger;
                            getFormRowByCaption(tbl , 'RequestNewColloApp', 0, true, true);
                            //RequestNewColloApp
                            getFormRowByCaption(tbl , 'RequestRSMApproval', 0, true, true);
                            //RequestNewColloApp
                            getFormRowByCaption(tbl , 'Workflow Comments', 0, true, true);

                            // show more
                            //if ($('a.ms-commandLink') != null)
                            // $('a.ms-commandLink').hide();
                            rlfiShowMore();

                            /**************
                            Task 306: Task Comment.
                            ***************/
                            // Hide comments span:
                            var ftr2 = getFormRowByCaption(tbl, 'Comments', 0, false, false);
                            if (ftr2 != null)
                            ftr2.find("td:last > span:last").hide();
                            }
                            }catch(err){}
                            });
                          </script>

No comments:

Post a Comment