secret
Last active

Developing Mobile Applications with Force.com and Sencha Touch - Part 3 - Complete Project

  • Download Gist
PocketCRM.page
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
<!--
========================================================
Name: PocketCRM
Type: Visualforce Page
Purpose: For Sencha Touch PocketCRM App
Created by: Don Robins - www.ForceMentor.com
Created on: August 1, 2012
Copyright 2012 Outformations, Inc.
 
Rev # Revised on Revised by Revision Description
----- ---------- -------------------------------------
1.0 08/01/2012 Don Robins Initial Release
=========================================================
-->
<apex:page docType="html-5.0" showHeader="false" standardStylesheets="false" cache="false">
<head>
 
<meta charset="UTF-8" />
<title>Pocket CRM</title>
 
<!-- Use the Visualforce tags for scripts and stylesheets rather than their HTML counterparts -->
<apex:includeScript value="http://cdn.sencha.io/try/touch/2.0.1/sencha-touch-all.js" />
<apex:stylesheet value="http://cdn.sencha.io/try/touch/2.0.1/resources/css/sencha-touch.css" />
 
<!-- Custom Application Style Sheet -->
<c:PocketCRM_CSS />
 
<!-- Our custom Visualforce component containing our Sencha Touch application -->
<c:PocketCRM_APP />
 
</head>
<body>
<!-- An animated image that displays while loading -->
<div id="appLoadingIndicator">
<div></div>
<div></div>
<div></div>
</div>
</body>
</apex:page>
PocketCRMLeadController.cls
Apex
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
//========================================================
// Name: PocketCRMLeadController
// Type: Controller
// Purpose: For Sencha Touch PocketCRM App
// Created by: Don Robins - www.ForceMentor.com
// Created on: August 1, 2012
// Copyright 2012 Outformations, Inc.
//
// Rev # Revised on Revised by Revision Description
// ----- ---------- -------------------------------------
// 1.0 08/01/2012 Don Robins Initial Release
// 1.1 10/01/2012 Don Robins v3
//=========================================================
public with sharing class PocketCRMLeadController{
 
public PocketCRMLeadController(){}
 
//========================================================================
//INNER CLASSES
//These support data request/response transport for remoting.
//========================================================================
 
//The server response expected by the ExtJS DirectProxy API methods.
public class Response {
public Boolean success;
public String errorMessage;
public List<SObject> records;
public Integer total;
Response() {
records = new List<SObject>();
success = true;
}
}
//One of the parameters supplied by the DirectProxy read method.
public class QueryRequest {
Integer start;
Integer recordCount;
List<Map<String, String>> sortParams;
String searchFilter = '';
Public QueryRequest() {
start = 1;
recordCount = 1;
}
 
Public QueryRequest(Integer pStart, Integer pRecordCount) {
start = pStart;
recordCount = pRecordCount;
}
 
}
 
//========================================================================
//REMOTE ACTION METHODS
//RemoteAction CRUD methods called by the Sencha touch Proxy in the data package.
//========================================================================
@RemoteAction
public static Response Query(QueryRequest qr){
 
Response resp = new Response();
 
//Enforce a limit on the number of rows requested.
final integer QUERY_LIMIT = 500;
if( qr.start >= QUERY_LIMIT ){
resp.success = false;
resp.errorMessage = 'Maximum number of records (' + String.valueOf(QUERY_LIMIT) + ') exceeded!';
return resp;
}
 
try {
getAllLeads(qr, resp);
} catch (Exception e) {
resp.success = false;
resp.errorMessage = 'Query failed: ' + e.getMessage();
}
 
return resp;
}
 
//=======================================================================
//PUBLIC CRUD REMOTE ACTION METHODS
//=======================================================================
 
@RemoteAction
public static Response Edit(List<Lead> LeadData){
return updateLeadList(LeadData);
}
 
@RemoteAction
public static Response Add(List<Lead> LeadData){
return insertLeadList(LeadData);
}
 
@RemoteAction
public static Response Destroy(List<Lead> LeadData){
return deleteLeadList(LeadData);
}
 
//=======================================================================
//PRIVATE HELPER METHODS
//=======================================================================
 
private static void getAllLeads(QueryRequest qr, Response resp){
 
//Page size is set in the Sencha store as recordCount.
Integer pageSize = qr.recordCount;
//Page number will be calculated.
Integer pageNumber = 0;
//Start is the record number indicating the start of the page.
if( qr.start > 0 ){
pageNumber = qr.start / pageSize;
}
 
//Calculate the offset for SOQL.
Integer offset = pageNumber * pageSize;
 
//Build the query in pieces.
String fieldList = 'Id,FirstName,LastName,Company,Title,Phone,MobilePhone,Email,Status';
String whereClause = (qr.searchFilter != '' ? 'WHERE Name LIKE \'' + qr.searchFilter + '\'' : '') ;
String orderByClause = 'LastName, FirstName';
 
//Construct a base query to which the page offsets will be added.
String baseQuery = 'SELECT ' + fieldList + ' FROM Lead ' + whereClause + ' ORDER BY ' + orderByClause;
 
//Construct a count query to pass back the total records matching a search criteria.
String baseCountQuery = 'SELECT COUNT() FROM Lead ' + whereClause ;
 
//Construct the fetch query with the offset.
String fetchQuery = baseQuery + ' LIMIT ' + pageSize + ' OFFSET ' + offset;
 
try {
//Set the count.
resp.total = Database.countQuery(baseCountQuery);
 
//Set the fetched recordset.
resp.records = Database.query(fetchQuery);
//Set the status flag.
resp.success = true;
 
} catch (Exception e) {
 
//Set the total count of records matching the query.
resp.total = 0;
//Set the recordset to return.
resp.records = new List<Lead>();
//Set the status flag.
resp.success = false;
 
}
}
 
private static Response insertLeadList(List<Lead> LeadData){
 
Response resp = new Response();
resp.success = true;
 
try {
INSERT LeadData;
} catch (Exception e) {
resp.success = false;
resp.errorMessage = 'Insert failed: ' + e.getMessage();
}
return resp;
}
 
private static Response updateLeadList(List<Lead> LeadData){
 
Response resp = new Response();
resp.success = true;
 
try {
UPDATE LeadData;
} catch (Exception e) {
resp.success = false;
resp.errorMessage = 'Update failed: ' + e.getMessage();
}
return resp;
}
 
private static Response deleteLeadList(List<Lead> LeadData){
 
Response resp = new Response();
resp.success = true;
 
try {
DELETE LeadData;
} catch (Exception e) {
resp.success = false;
resp.errorMessage = 'Deletion failed: ' + e.getMessage();
}
return resp;
}
 
}
PocketCRM_APP.component
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718
<!--
========================================================
Name: PocketCRM_APP
Type: Visualforce Custom Component
Purpose: For Sencha Touch PocketCRM App
Created by: Don Robins - www.ForceMentor.com
Created on: August 1, 2012
Copyright 2012 Outformations, Inc.
 
Rev # Revised on Revised by Revision Description
----- ---------- -------------------------------------
1.0 08/01/2012 Don Robins Initial Release
1.1 10/01/2012 Don Robins v3
=========================================================
-->
 
<apex:component controller="PocketCRMLeadController" >
<script type="text/javascript">
 
//================================================================================================================
//APPLICATION
//The Application class is the entry point into your Sencha Touch application.
//================================================================================================================
Ext.application({
name: "PocketCRM",
 
//Load the various MVC components into memory.
models: ["Lead"],
stores: ["Leads"],
controllers: ["Leads"],
views: ["LeadsList","LeadEditor"],
//The application's startup routine once all components are loaded.
launch: function () {
 
//Instantiate your main list view for Leads.
var leadsListView = {
xtype: "leadslistview"
};
 
var leadEditorView = {
xtype: "leadeditorview"
};
 
//Launch the primary fullscreen view and pass in the list view.
Ext.Viewport.add([leadsListView, leadEditorView]);
 
}
 
});
 
 
//================================================================================================================
//VIEWS
//Views display data to your users and gather input from them; they also emit events about your user interaction.
//================================================================================================================
 
//The Lead list view.
Ext.define("PocketCRM.view.LeadsList", {
extend: "Ext.Container",
 
//It uses the base list class.
requires: "Ext.dataview.List",
alias: "widget.leadslistview",
 
config: {
 
//Take up the full space available in the parent container.
layout: {
type: 'fit'
},
 
 
//Add the components to include within the list view.
items: [
{
xtype: "toolbar",
title: "PocketCRM",
docked: "top",
 
items: [
{
xtype: 'spacer'
},
{
xtype: "button",
text: 'New',
ui: 'action',
itemId: "newButton"
}
]
},
{
xtype: "toolbar",
docked: "bottom",
itemId: "bottomToolBar",
items: [
{xtype: 'spacer'}
,
{
xtype: 'searchfield',
itemId:'leadSearchField',
placeHolder: 'Name Contains...'
},
{
xtype: "button",
iconCls: "search",
iconMask: true,
itemId: "syncButton"
}
,
{xtype: 'spacer'}
]
},
{
//The main list and its properties.
xtype: "list",
store: "Leads",
itemId:"leadsList",
onItemDisclosure: true,
indexBar: true,
grouped: true,
disableSelection: false,
 
plugins: [
{
xclass: 'Ext.plugin.ListPaging',
autoPaging: true
}
],
 
//The template for display if the Store is empty of records.
//Note the style to control visual presentation.
loadingText: "Loading Leads...",
emptyText: '<div class="leads-list-empty-text">No leads found.</div>',
 
//The template for the display of each list item representing one record.
//One row will display for each record in the data Store.
//The fields referenced are from the entity's Model.
itemTpl: '<div class="list-item-line-main">{LastName}, {FirstName}</div>' +
'<div class="list-item-line-detail">{Company}</div>' +
'<div class="list-item-line-detail">{Title} - Phone: {Phone} </div>' +
'<div class="list-item-line-detail">{Email}</div>',
}],
listeners: [{
delegate: "#newButton",
event: "tap",
fn: "onNewButtonTap"
}, {
delegate: "#syncButton",
event: "tap",
fn: "onSyncButtonTap"
}, {
delegate: "#leadsList",
event: "disclose",
fn: "onLeadsListDisclose"
}, {
delegate: "#leadSearchField",
event: "clearicontap",
fn: "onLeadSearchFieldClearIconTap"
},
{
delegate: "#leadsList",
event: "refresh",
fn: "onLeadsListRefresh",
},
{
//Listener on the view's Activate event fires when redisplayed by transition.
event: "activate",
fn: "onLeadsListViewActivate",
}]
},
 
onSyncButtonTap: function () {
console.log("syncLeadCommand");
this.fireEvent("syncLeadCommand", this);
},
 
onNewButtonTap: function () {
console.log("newLeadCommand");
this.fireEvent("newLeadCommand", this);
},
 
onLeadsListDisclose: function (list, record, target, index, evt, options) {
console.log("editLeadCommand");
this.fireEvent('editLeadCommand', this, record);
},
 
onLeadSearchFieldClearIconTap: function () {
console.log("clearSearchLeadCommand");
this.fireEvent('clearSearchLeadCommand', this);
},
onLeadsListRefresh: function () {
console.log("onLeadsListRefresh");
this.updateListCounter();
},
 
onLeadsListViewActivate: function () {
console.log("onLeadsListViewActivate");
this.updateListCounter();
},
 
//Function to get count of records in the list and show on the search button's badge.
updateListCounter: function () {
var listCount = Ext.getStore("Leads").getCount();
this.getComponent("bottomToolBar").getComponent("syncButton").setBadgeText(listCount);
}
 
});
 
//The Lead form view.
Ext.define("PocketCRM.view.LeadEditor", {
extend: "Ext.form.Panel",
requires: "Ext.form.FieldSet",
alias: "widget.leadeditorview",
 
config: {
 
scrollable: 'vertical',
 
items: [
{
xtype: "toolbar",
docked: "top",
title: "Edit Lead",
items: [
{
xtype: "button",
ui: "back",
text: "Home",
itemId: "backButton"
},
{ xtype: "spacer" },
{
xtype: "button",
ui: "action",
text: "Save",
itemId: "saveButton"
}
]
},
{
xtype: "toolbar",
docked: "bottom",
items: [
{
xtype: "button",
iconCls: "trash",
iconMask: true,
itemId: "deleteButton"
}
]
},
{ xtype: "fieldset",
title: 'Lead Info',
items: [
{
xtype: 'textfield',
name: 'FirstName',
label: 'First Name'
},
{
xtype: 'textfield',
name: 'LastName',
label: 'Last Name',
required: true
},
{
xtype: 'textfield',
name: 'Company',
label: 'Company',
required: true
},
{
xtype: 'textfield',
name: 'Title',
label: 'Title'
},
{
xtype: 'selectfield',
name: 'Status',
label: 'Status',
required: true,
value: 'Open - Not Contacted',
options: [
{text: 'Open - Not Contacted', value: 'Open - Not Contacted'},
{text: 'Working - Contacted', value: 'Working - Contacted'},
{text: 'Closed - Converted', value: 'Closed - Converted'},
{text: 'Closed - Not Converted', value: 'Closed - Not Converted'}
],
 
},
]
},
{ xtype: "fieldset",
title: 'Contact Info',
items: [
{
xtype : 'textfield',
name : 'Phone',
label : 'Phone',
component: {type: 'tel'}
},
{
xtype : 'textfield',
name : 'MobilePhone',
label : 'Mobile',
component: {type: 'tel'}
},
{
xtype: 'emailfield',
name: 'Email',
label: 'Email Address'
},
]
},
],
listeners: [
{
delegate: "#backButton",
event: "tap",
fn: "onBackButtonTap"
},
{
delegate: "#saveButton",
event: "tap",
fn: "onSaveButtonTap"
},
{
delegate: "#deleteButton",
event: "tap",
fn: "onDeleteButtonTap"
}
]
},
 
onSaveButtonTap: function () {
console.log("saveLeadCommand");
this.fireEvent("saveLeadCommand", this);
},
 
onDeleteButtonTap: function () {
console.log("deleteLeadCommand");
Ext.Msg.confirm("Delete Lead", "Are you sure?", function(button){
if (button == 'yes') {
this.fireEvent("deleteLeadCommand", this);
} else {
return false;
}
}, this);
},
 
onBackButtonTap: function () {
console.log("backToHomeCommand");
this.fireEvent("backToHomeCommand", this);
}
 
});
 
//================================================================================================================
//CONTROLLERS
//Controllers manage the communication of your application and the coordination between the views and the model;
//they listen for the events emitted by the views and react accordingly.
//================================================================================================================
 
//The controller for the Leads list view
Ext.define("PocketCRM.controller.Leads", {
extend: "Ext.app.Controller",
 
config: {
 
refs: {
// We're going to lookup our views by alias.
leadsListView: "leadslistview",
leadEditorView: "leadeditorview",
leadsList: "#leadsList",
 
//Add a new search field.
leadsListSearchField: "#leadSearchField"
},
 
control: {
leadsListView: {
// The commands fired by the list container.
syncLeadCommand: "onSyncLeadCommand",
newLeadCommand: "onNewLeadCommand",
editLeadCommand: "onEditLeadCommand",
//Add an event when clearing the search text.
clearSearchLeadCommand: "onClearSearchLeadCommand"
},
 
leadEditorView: {
// The commands fired by the note editor.
saveLeadCommand: "onSaveLeadCommand",
deleteLeadCommand: "onDeleteLeadCommand",
backToHomeCommand: "onBackToHomeCommand"
}
 
}
},
 
//View Transitions
slideLeftTransition: { type: 'slide', direction: 'left' },
slideRightTransition: { type: 'slide', direction: 'right' },
 
//View Transition Helper functions
activateLeadEditor: function (record) {
var leadEditorView = this.getLeadEditorView();
leadEditorView.setRecord(record);
Ext.Viewport.animateActiveItem(leadEditorView, this.slideLeftTransition);
},
 
activateLeadsList: function () {
Ext.Viewport.animateActiveItem(this.getLeadsListView(), this.slideRightTransition);
},
 
onSyncLeadCommand: function () {
console.log("onSyncLeadCommand");
 
this.loadList();
 
},
 
onNewLeadCommand: function () {
console.log("onNewLeadCommand");
 
//Set a default value for the Status selectfield.
var newLead = Ext.create("PocketCRM.model.Lead", {
Status: "Open - Not Contacted"
});
 
this.activateLeadEditor(newLead);
},
 
onEditLeadCommand: function (list, record) {
console.log("onEditLeadCommand");
this.activateLeadEditor(record);
},
 
onSaveLeadCommand: function () {
console.log("onSaveLeadCommand");
//Update the field values in the record.
var leadEditorView = this.getLeadEditorView();
var currentLead = leadEditorView.getRecord();
var newValues = leadEditorView.getValues();
this.getLeadEditorView().updateRecord(currentLead);
 
//Check for validation errors.
var errors = currentLead.validate();
if (!errors.isValid()) {
var msg = '';
errors.each(function(error) {
msg += error.getMessage() + '<br/>';
});
console.log('Errors: ' + msg);
Ext.Msg.alert('Please correct errors!', msg, Ext.emptyFn);
currentLead.reject();
return;
}
 
//Get a ref to the store.
var leadsStore = Ext.getStore("Leads");
 
//Add new record to the store.
if (null == leadsStore.findRecord('id', currentLead.data.id)) {
leadsStore.add(currentLead);
}
 
//Resync the proxy and activate the list.
leadsStore.sync();
this.activateLeadsList();
},
 
onDeleteLeadCommand: function () {
console.log("onDeleteLeadCommand");
//Get a ref to the form and its record.
var leadEditorView = this.getLeadEditorView();
var currentLead = leadEditorView.getRecord();
 
//Get a ref to the store and remove it.
var leadsStore = Ext.getStore("Leads");
leadsStore.remove(currentLead);
//Resync the proxy and activate the list.
leadsStore.sync();
this.activateLeadsList();
},
 
onBackToHomeCommand: function () {
console.log("onBackToHomeCommand");
this.activateLeadsList();
},
 
//Reload the list when clearing the search value.
onClearSearchLeadCommand: function () {
console.log("onClearSearchLeadCommand");
//Get a ref to the search field.
var leadSearchField = this.getLeadsListSearchField();
leadSearchField.setValue('');
console.log("Cleared Field Value: " + leadSearchField.getValue());
 
this.loadList();
},
 
//Add separate load function to be called by multiple event handlers.
loadList: function () {
 
//Get a ref to the store and remove it.
var leadsStore = Ext.getStore("Leads");
 
//Get any search text.
var leadSearchField = this.getLeadsListSearchField();
var searchText = leadSearchField.getValue();
console.log("Search Field Value in reSync: " + searchText);
 
if (searchText.length > 0 && searchText.length < 2) {
var msg = 'Search requires more text.';
Ext.Msg.alert('Please correct errors!', msg, Ext.emptyFn);
return;
}
 
//Add wild cards.
if (searchText != '') {
//Surround the search value with a wildcard for SOQL search.
searchText = '%' + searchText + '%';
} else {
//Set wildcard for wide open filter.
searchText = '%';
}
console.log("Search Field Value: " + searchText);
 
//Set the value of the searchFilter param to pass with the query.
var model = Ext.ModelMgr.getModel('PocketCRM.model.Lead');
model.getProxy().setExtraParam('searchFilter', searchText);
 
//Clear all data in the store before loading it.
//This is necessary to make sure that the proxy doesn't get confused by
//the loss of records not reloaded with a new filter.
//Without the clear(), the proxy assumes a deletion was processed and
//calls a destroy to be executed on missing records with the next sync() operation.
leadsStore.getData().clear();
leadsStore.loadPage(1);
//Reshow the list.
this.activateLeadsList();
},
// Base Class functions.
launch: function () {
console.log("launch");
this.callParent(arguments);
//Load up the Store associated with the controller and its views.
console.log("load Leads");
this.loadList();
},
 
init: function() {
 
this.callParent(arguments);
console.log("init");
 
//Listen for exceptions observed by the proxy so we can report them and clean up.
Ext.getStore('Leads').getProxy().addListener('exception', function (proxy, response, operation, options) {
// only certain kinds of errors seem to have useful information returned from the server
if (response) {
if (response.errorMessage) {
Ext.Msg.alert('Error', response.errorMessage);
} else {
Ext.Msg.alert('Error', operation.config.action + ' failed: ' + response.errorMessage);
}
} else {
Ext.Msg.alert('Error', operation.config.action + ' failed for an unknown reason: proxy = ' + proxy);
}
});
 
},
 
});
 
 
//================================================================================================================
//MODELS
//Models are the objects on your application.
//================================================================================================================
//AN IMPORTANT NOTE: if your org has a registered namespace, you MUST reference the Apex controller name in the
//proxy your JavaScript with your org's namespace. If you fail to do this, you will get a a JavaScript error that
//the Apex controller can NOT be found!
//================================================================================================================
//The Lead model will include whatever fields are necssary to manage.
Ext.define("PocketCRM.model.Lead", {
extend: "Ext.data.Model",
 
config: {
idProperty: 'Id',
 
fields: [
{ name: 'Id', type: 'string', persist: false},
{ name: 'Name', type: 'string', persist: false },
{ name: 'FirstName', type: 'string' },
{ name: 'LastName', type: 'string' },
{ name: 'Company', type: 'string' },
{ name: 'Title', type: 'string' },
{ name: 'Phone', type: 'string' },
{ name: 'MobilePhone', type: 'string' },
{ name: 'Email', type: 'string' },
{ name: 'Status', type: 'string' }
],
 
validations: [
{ type: 'presence', field: 'LastName', message: 'Enter a last name.' },
{ type: 'presence', field: 'Company', message: 'Enter a company.' },
{ type: 'presence', field: 'Status', message: 'Select a status.' }
],
 
//Bind each CRUD functions to a @RemoteAction method in the Apex controller
proxy: {
type: 'direct',
api: {
read: PocketCRMLeadController.Query,
create: PocketCRMLeadController.Add,
update: PocketCRMLeadController.Edit,
destroy: PocketCRMLeadController.Destroy
},
limitParam: 'recordCount', // because "limit" is an Apex keyword
sortParam: 'sortParams', // because "sort" is a keyword too
pageParam: false, // we don't use this in the controller, so don't send it
extraParams: ( { 'searchFilter':'%' } ),
reader: {
type: 'json',
rootProperty: 'records',
messageProperty: 'errorMessage'
},
writer: {
type: 'json',
root: 'records',
writeAllFields: false, // otherwise empty fields will transmit as empty strings, instead of "null"/not present
allowSingle: false, // need to always be an array for code simplification
encode: false // docs say "set this to false when using DirectProxy"
}
 
}
},
 
});
 
 
//================================================================================================================
//PROXY RELATED EXTENSIONS
//================================================================================================================
//AN IMPORTANT NOTE: if your org has ANY installed packages, you MUST reference the Apex controller name in your
//JavaScript with your org's namespace. If you fail to do this, you will get a a JavaScript error that the Apex
//controller can NOT be found!
//================================================================================================================
//Adjust our read method to add a function that Touch expects to see to get Arguments.
PocketCRMLeadController.Query.directCfg.method.getArgs =
function (params, paramOrder, paramsAsHash) {
console.log('getArgs: ' + params.data);
return [params];
}
 
Ext.data.proxy.Direct.prototype.createRequestCallback =
function(request, operation, callback, scope){
var me = this;
return function(data, event){
console.log('createRequestCallback: ' + operation);
me.processResponse(event.status, operation, request, data, callback, scope);
};
};
 
 
//================================================================================================================
//STORES
//Stored serve as the client-side cache of your data; they loading data into your app's views.
//================================================================================================================
 
Ext.define("PocketCRM.store.Leads", {
extend: "Ext.data.Store",
requires: "Ext.data.proxy.LocalStorage",
 
config: {
 
model: "PocketCRM.model.Lead",
autoLoad: true,
pageSize: 25,
 
//Create a grouping; be certain to use a field with content or you'll get errors!
groupField: "Status",
groupDir: "ASC",
//Create additional sorts for within the Group.
sorters: [{ property: 'LastName', direction: 'ASC'}, { property: 'FirstName', direction: 'ASC'}],
},
 
listeners: {
load: function(){
console.log('store.load(): loaded!');
},
}
 
});
 
</script>
</apex:component>
PocketCRM_CSS.component
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
<!--
========================================================
Name: PocketCRM_CSS
Type: Visualforce Custom Component
Purpose: For Sencha Touch PocketCRM App
Created by: Don Robins - www.ForceMentor.com
Created on: August 1, 2012
Copyright 2012 Outformations, Inc.
 
Rev # Revised on Revised by Revision Description
----- ---------- -------------------------------------
1.0 08/01/2012 Don Robins Initial Release
1.1 10/01/2012 Don Robins v3
=========================================================
-->
<apex:component>
<style type="text/css">
/**
* Example of an initial loading indicator.
* It is recommended to keep this as minimal as possible to provide instant feedback
* while other resources are still being loaded for the first time
*/
html, body {
height: 100%;
background-color: #1985D0
}
#appLoadingIndicator {
position: absolute;
top: 50%;
margin-top: -15px;
text-align: center;
width: 100%;
height: 30px;
-webkit-animation-name: appLoadingIndicator;
-webkit-animation-duration: 0.5s;
-webkit-animation-iteration-count: infinite;
-webkit-animation-direction: linear;
}
#appLoadingIndicator > * {
background-color: #FFFFFF;
display: inline-block;
height: 30px;
-webkit-border-radius: 15px;
margin: 0 5px;
width: 30px;
opacity: 0.8;
}
@-webkit-keyframes appLoadingIndicator {
0% {
opacity: 0.8
}
50% {
opacity: 0
}
100% {
opacity: 0.8
}
}
/**
* PocketCRM Custom styles
*/
/* Increase height of list item so title and narrative lines fit */
.x-list .x-list-item .x-list-item-label {
min-height: 4.5em!important;
}
/* Move up the disclosure button to account for the list item height increase */
.x-list .x-list-disclosure {
position: absolute;
bottom: 0.85em;
right: 0.44em;
}
.list-item-line-main {
float:left;
width:100%;
font-size:100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding-right:25px;
line-height:115%;
}
.list-item-line-detail {
float:left;
width:95%;
font-size:60%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding-right:25px;
padding-left:10px;
line-height:125%;
}
.x-item-selected .list-item-line-detail {
color:#ffffff;
font-weight: bold;
}
.leads-list-empty-text {
padding:10px;
}
</style>
</apex:component>

An important note: if your org has a registered namespace, you MUST reference the Apex controller name in your JavaScript with your org's namespace. If you fail to do this, you will get a JavaScript error that the Apex controller can NOT be found!

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.