Guest User

Untitled

a guest
Apr 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.18 KB | None | 0 0
  1. <apex:page controller="FormerAuthorController" sidebar="false" applyHtmlTag="true">
  2.  
  3. <apex:form >
  4. <apex:pageMessages id="errors" />
  5.  
  6. <apex:pageBlock title="Former Author Payment!" mode="edit">
  7.  
  8. <table width="100%" border="0">
  9. <tr>
  10. <td width="200" valign="top">
  11.  
  12.  
  13. <apex:pageBlock title="Parameters" mode="edit" id="criteria">
  14.  
  15. <script type="text/javascript">
  16. function doSearch() {
  17. searchServer(
  18. document.getElementById("year").value,
  19. document.getElementById("fiscal").options[document.getElementById("fiscal").selectedIndex].value
  20. );
  21. }
  22. </script>
  23.  
  24. <apex:actionFunction name="searchServer" action="{!runSearch}" rerender="results,debug,errors">
  25. <apex:param name="year" value="" />
  26. <apex:param name="fiscal" value="" />
  27. </apex:actionFunction>
  28.  
  29. <table cellpadding="2" cellspacing="2">
  30. <tr>
  31. <td style="font-weight:bold;">Fiscal-Quarter<br/>
  32. <select id="fiscal" onchange="doSearch();">
  33. <option value=""></option>
  34. <apex:repeat value="{!fiscal}" var="quarter">
  35. <option value="{!quarter}">{!quarter}</option>
  36. </apex:repeat>
  37. </select>
  38. </td>
  39. </tr>
  40. <tr>
  41. <td style="font-weight:bold;">Year<br/>
  42. <input type="number" id="year" onkeyup="doSearch();"/>
  43. </td>
  44. </tr>
  45. <!-- tr>
  46. <td style="font-weight:bold;">Last Name<br/>
  47. <input type="text" id="lastName" onkeyup="doSearch();"/>
  48. </td>
  49. </tr>
  50. <tr>
  51. <td style="font-weight:bold;">Account<br/>
  52. <input type="text" id="accountName" onkeyup="doSearch();"/>
  53. </td>
  54. </tr -->
  55.  
  56. </table>
  57.  
  58. </apex:pageBlock>
  59.  
  60. </td>
  61. <td valign="top">
  62.  
  63. <apex:pageBlock mode="edit" id="results">
  64.  
  65.  
  66. <apex:pageBlockButtons >
  67. <apex:commandButton value="Submit" action="{!submitForApproval}"/>
  68. <apex:commandButton value="Cancel" action="{!Cancel}"/>
  69. <apex:commandButton value="Approve" action="{!Approve}"/>
  70. <apex:commandButton value="Reject" action="{!Reject}" />
  71. </apex:pageBlockButtons>
  72. <apex:pageBlockButtons >
  73. <apex:commandButton value="First" action="{!Beginning}"/>
  74. <apex:commandButton value="Previous" action="{!Previous}"/>
  75. <apex:commandButton value="Next" action="{!Next}"/>
  76. <apex:commandButton value="Last" action="{!End}" />
  77.  
  78. </apex:pageBlockButtons>
  79. <apex:pageBlockTable value="{!monAct}" var="monRec">
  80.  
  81. <!-- apex:column >
  82. <apex:facet name="header">
  83. <apex:inputCheckbox>
  84. <apex:actionSupport event="onClick" action="{!getSelected}" reRender="selection"/>
  85. </apex:inputCheckbox>
  86. </apex:facet>
  87. <apex:inputCheckbox value="{!monRec.Checkbox__c}" id="checkdone">
  88. <apex:actionSupport event="onClick" action="{!getSelected}" reRender="selection"/>
  89. </apex:inputCheckbox>
  90. </apex:column -->
  91.  
  92. <apex:column >
  93. <apex:facet name="header">
  94. <c:CheckAllorNone />
  95. </apex:facet>
  96. <apex:inputCheckbox value="{!monRec.Checkbox__c}"/>
  97. </apex:column>
  98. <apex:column >
  99. <apex:facet name="header">
  100. <apex:commandLink value="GID" action="{!toggleSort}" rerender="results,debug">
  101. <apex:param name="sortField" value="GID__c" assignTo="{!sortField}"/>
  102. </apex:commandLink>
  103. </apex:facet>
  104. <apex:outputField value="{!monRec.GID__c}"/>
  105. </apex:column>
  106. <apex:column >
  107. <apex:facet name="header">
  108. <apex:commandLink value="Month" action="{!toggleSort}" rerender="results,debug">
  109. <apex:param name="sortField" value="Month_Text__c" assignTo="{!sortField}"/>
  110. </apex:commandLink>
  111. </apex:facet>
  112. <apex:outputField value="{!monRec.Month_Text__c}"/>
  113. </apex:column>
  114. <apex:column >
  115. <apex:facet name="header">
  116. <apex:commandLink value="Quarter" action="{!toggleSort}" rerender="results,debug">
  117. <apex:param name="sortField" value="Quarter__c" assignTo="{!sortField}"/>
  118. </apex:commandLink>
  119. </apex:facet>
  120. <apex:outputField value="{!monRec.Quarter__c}"/>
  121. </apex:column>
  122. <apex:column >
  123. <apex:facet name="header">
  124. <apex:commandLink value="Year" action="{!toggleSort}" rerender="results,debug">
  125. <apex:param name="sortField" value="year" assignTo="{!sortField}"/>
  126. </apex:commandLink>
  127. </apex:facet>
  128. <apex:outputField value="{!monRec.Year__c}"/>
  129. </apex:column>
  130.  
  131.  
  132. </apex:pageBlockTable>
  133.  
  134. </apex:pageBlock>
  135.  
  136. </td>
  137. </tr>
  138. </table>
  139.  
  140. <apex:pageBlock title="Debug - SOQL" id="debug">
  141. <apex:outputText value="{!debugSoql}" />
  142. </apex:pageBlock>
  143.  
  144. </apex:pageBlock>
  145.  
  146. </apex:form>
  147.  
  148. public with sharing class FormerAuthorController {
  149. public List<Monthly_Activity__c> monAct {get; set;}
  150. private String soql{get; set;}
  151. public Boolean checkAll{get; set;}
  152. private String fiscalPeriod;
  153. private String yearValue;
  154. private static final String EDITORIAL_GROUP_NAME = 'Editorial';
  155. private static final String FINANCIAL_GROUP_NAME = 'Finance';
  156. private integer counter=0; //keeps track of the offset
  157. private integer list_size=25; //sets the page size or number of rows
  158. public integer total_size; //used to show user the total size of the list
  159.  
  160. //List<Monthly_Activity__c> selectedRecords = new List<Monthly_Activity__c>();
  161.  
  162. private static Id financeGroupId
  163. {
  164. get
  165. {
  166. if (financeGroupId == null)
  167. {
  168. financeGroupId = [SELECT Id FROM Group WHERE Name = :FINANCIAL_GROUP_NAME][0].Id;
  169. }
  170. return financeGroupId;
  171. }
  172. private set;
  173. }
  174.  
  175. private static Id editorialGroupId
  176. {
  177. get
  178. {
  179. if (editorialGroupId == null)
  180. {
  181. editorialGroupId = [SELECT Id FROM Group WHERE Name = :EDITORIAL_GROUP_NAME][0].Id;
  182. }
  183. return editorialgroupId;
  184. }
  185. private set;
  186. }
  187.  
  188. private static Id submitterProfileId
  189. {
  190. get
  191. {
  192. if (submitterProfileId == null)
  193. {
  194. submitterProfileId = [SELECT Id FROM Profile WHERE Name = 'Submitters'][0].Id;
  195. }
  196. return submitterProfileId;
  197. }
  198. private set;
  199. }
  200.  
  201. private static Id financeProfileId
  202. {
  203. get
  204. {
  205. if (financeProfileId == null)
  206. {
  207. financeProfileId = [SELECT Id FROM Profile WHERE Name = 'Finance'][0].Id;
  208. }
  209. return financeProfileId;
  210. }
  211. private set;
  212. }
  213.  
  214. private static Id editorialProfileId
  215. {
  216. get
  217. {
  218. if (editorialProfileId == null)
  219. {
  220. editorialProfileId = [SELECT Id FROM Profile WHERE Name = 'Editorial'][0].Id;
  221. }
  222. return editorialProfileId;
  223. }
  224. private set;
  225. }
  226.  
  227.  
  228. private static Id adminProfileId
  229. {
  230. get
  231. {
  232. if (adminProfileId == null)
  233. {
  234. adminProfileId = [SELECT Id FROM Profile WHERE Name = 'System Administrator'][0].Id;
  235. }
  236. return adminProfileId;
  237. }
  238. private set;
  239. }
  240.  
  241. // the current sort direction. defaults to asc
  242. public String sortDir {
  243. get{
  244. if(sortDir == null){
  245. sortDir = 'asc';
  246. }
  247. return sortDir;
  248. }
  249. set;
  250. }
  251.  
  252. // the current field to sort by. defaults to last name
  253. public String sortField {
  254. get{
  255. if (sortField == null) {
  256. sortField = 'Year__c';
  257. } return sortField;
  258. }
  259. set;
  260. }
  261.  
  262. // format the soql for display on the visualforce page
  263. public String debugSoql {
  264. get{
  265. return soql + ' order by ' + sortField + ' ' + sortDir + ' limit '+list_size+' '+ 'offset '+counter;
  266. }
  267. set;
  268. }
  269.  
  270. public FormerAuthorController(){
  271. total_size = [SELECT count() FROM Monthly_Activity__c WHERE Contract_Status__c =:'Former Author'];
  272.  
  273. }
  274.  
  275. // toggles the sorting of query from asc<-->desc
  276. public void toggleSort() {
  277. // simply toggle the direction
  278. sortDir = sortDir.equals('asc') ? 'desc' : 'asc';
  279. // run the query again
  280. runQuery();
  281. }
  282.  
  283. // runs the actual query
  284. public void runQuery() {
  285.  
  286. try {
  287. //monAct = Database.query(soql + ' order by ' + sortField + ' ' + sortDir + ' '+' Limit '+list_size+' '+' OFFSET '+counter);
  288. monAct = Database.query(debugSoql);
  289. system.debug('RUN QUERY ' + monAct);
  290. } catch (Exception e) {
  291. ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Something Went Wrong. Contact System Adminstrator!'));
  292. system.debug('Error Message ***'+ e.getMessage());
  293. }
  294.  
  295. }
  296.  
  297. // runs the search with parameters passed via Javascript
  298. public PageReference runSearch() {
  299. system.debug('RUN SEARCH');
  300. String fiscal = Apexpages.currentPage().getParameters().get('fiscal');
  301. fiscalPeriod = fiscal;
  302. String year = Apexpages.currentPage().getParameters().get('year');
  303. yearValue = year;
  304. system.debug('FISCAL '+ fiscal);
  305. system.debug('YEAR '+ year);
  306. soql = 'SELECT Id, Name, Month__c, Checkbox__c FROM Monthly_Activity__c WHERE Contract_Status__c = 'Former Author'';
  307. if (!year.equals(''))
  308. soql += ' and Year__c ='+ year;
  309. if (!fiscal.equals(''))
  310. soql += ' and Quarter__c LIKE '' +String.escapeSingleQuotes(fiscal)+''';
  311.  
  312.  
  313. // run the query again
  314. runQuery();
  315. system.debug('RUN SEARCH QUERY');
  316. return null;
  317. }
  318.  
  319. // use apex describe to build the picklist values
  320. public List<String> fiscal {
  321. get {
  322. if (fiscal == null) {
  323.  
  324. fiscal = new List<String>();
  325. Schema.DescribeFieldResult field = Monthly_Activity__c.Fiscal_Quarter__c.getDescribe();
  326.  
  327. for (Schema.PicklistEntry f : field.getPicklistValues())
  328. fiscal.add(f.getLabel());
  329.  
  330. }
  331. return fiscal;
  332. }
  333. set;
  334. }
  335.  
  336.  
  337. //Approval Code
  338.  
  339. public void beginApprovalProcess(Monthly_Activity__c monAct){
  340. Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
  341. req.setComments('Submitting Records for Approval via VisualForce Page');
  342. req.setObjectId(monAct.id);
  343.  
  344. }
  345.  
  346. // Button Code
  347.  
  348.  
  349. public void submitForApproval(){
  350. if(fiscalPeriod <> Null && yearValue <> Null) {
  351. if(UserInfo.getProfileId()== submitterProfileId || UserInfo.getProfileId()== adminProfileId){
  352. //beginApprovalProcess();
  353.  
  354. }
  355. }
  356. }
  357.  
  358.  
  359. public PageReference Cancel(){
  360. PageReference page = new PageReference('/FormerAuthorPage');
  361. page.setRedirect(true);
  362. return page;
  363. }
  364.  
  365. public PageReference Approve(){
  366. if(fiscalPeriod <> Null && yearValue <> Null) {
  367. if(UserInfo.getProfileId()== financeProfileId || UserInfo.getProfileId()== editorialProfileId){
  368.  
  369.  
  370. }
  371. }
  372. PageReference page = new PageReference('/FormerAuthorPage');
  373. page.setRedirect(true);
  374. return page;
  375. }
  376.  
  377. public PageReference Reject(){
  378. if(fiscalPeriod <> Null && yearValue <> Null) {
  379. if(UserInfo.getProfileId()== financeProfileId || UserInfo.getProfileId()== editorialProfileId){
  380.  
  381.  
  382. }
  383. }
  384. PageReference page = new PageReference('/FormerAuthorPage');
  385. page.setRedirect(true);
  386. return page;
  387. }
  388.  
  389. // Pagination Code
  390.  
  391. public PageReference Beginning() { //user clicked first
  392. counter = 0;
  393. runQuery();
  394. return null;
  395. }
  396.  
  397. public PageReference Previous() { //user clicked previous
  398. counter -= list_size;
  399. runQuery();
  400. return null;
  401. }
  402.  
  403. public PageReference Next() { //user clicked next
  404. counter += list_size;
  405. runQuery();
  406. return null;
  407. }
  408.  
  409. public PageReference End() { //user clicked last
  410. counter = total_size - math.mod(total_size, list_size);
  411. runQuery();
  412. return null;
  413. }
  414.  
  415. public Boolean getDisablePrevious() {
  416. //this will disable the previous and beginning buttons
  417. if (counter>0) return false;
  418. else return true;
  419.  
  420. }
  421.  
  422. public Boolean getDisableNext() { //this will disable the next and end buttons
  423. if (counter + list_size < total_size)
  424. return false; else return true;
  425.  
  426. }
  427.  
  428. public Integer getTotal_size() {
  429. return total_size;
  430. }
  431.  
  432. public Integer getPageNumber() {
  433. return counter/list_size + 1;
  434. }
  435.  
  436. public Integer getTotalPages() {
  437. if (math.mod(total_size, list_size) > 0) {
  438. return total_size/list_size + 1;
  439. } else {
  440. return (total_size/list_size);
  441. }
  442. }
  443.  
  444. <apex:component >
  445. <script>
  446. function cvCheckAllOrNone(allOrNoneCheckbox) {
  447.  
  448. // Find parent table
  449. var container = allOrNoneCheckbox;
  450. while (container.tagName != "TABLE") {
  451. container = container.parentNode;
  452. }
  453.  
  454. // Switch all checkboxes
  455. var inputs = container.getElementsByTagName("input");
  456. var checked = allOrNoneCheckbox.checked;
  457. for (var i = 0; i < inputs.length; i++) {
  458. var input = inputs.item(i);
  459. if (input.type == "checkbox") {
  460. if (input != allOrNoneCheckbox) {
  461. input.checked = checked;
  462. }
  463. }
  464. }
  465. }
  466. </script>
  467.  
  468. <apex:inputCheckbox onclick="cvCheckAllOrNone(this)" title="Toggle All Rows"/>
Add Comment
Please, Sign In to add comment