Created
November 8, 2012 21:25
-
-
Save wskidmore/4041735 to your computer and use it in GitHub Desktop.
SLXMobile v2, add actions to home screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define('Mobile/Training/ApplicationModule', [ | |
'dojo/_base/declare', | |
'dojo/_base/lang', | |
'dojo/_base/connect', | |
'dojo/string', | |
'dojo/query', | |
'dojo/dom-attr', | |
'dojo/dom-class', | |
'Mobile/SalesLogix/Format', | |
'Sage/Platform/Mobile/ApplicationModule', | |
'Mobile/SalesLogix/Views/Home' | |
], function( | |
declare, | |
lang, | |
connect, | |
string, | |
query, | |
domAttr, | |
domClass, | |
format, | |
ApplicationModule, | |
Home | |
) { | |
// variables outside the return are private to this file and is executed once on load. | |
var viewFilters = { | |
'account_list': { | |
'open': false | |
}, | |
'contact_list': { | |
'open': false | |
}, | |
'opportunity_list': { | |
'open': true | |
}, | |
'ticket_list': { | |
'open': false | |
}, | |
'calendar_daylist': { | |
'open': false | |
}, | |
'history_list': { | |
'open': false | |
} | |
}; | |
return declare('Mobile.Training.ApplicationModule', ApplicationModule, { | |
loadViews: function() { | |
this.inherited(arguments); | |
}, | |
loadCustomizations: function() { | |
this.inherited(arguments); | |
// turn on actions, override row template to add data-view | |
lang.extend(Home, { | |
allowSelection: true, | |
enableActions: true, | |
rowTemplate: new Simplate([ | |
'<li data-action="{%= $.action %}" {% if ($.view) { %}data-key="{%= $.view %}" data-view="{%= $.view %}"{% } %}>', | |
'<button data-action="selectEntry" class="list-item-selector button">', | |
'<img src="{%= $.icon || $$.selectIcon %}" class="icon" />', | |
'</button>', | |
'<div class="list-item-content">{%! $$.itemTemplate %}</div>', | |
'</li>' | |
]), | |
actions: [ | |
{ | |
id: 'new', | |
icon: 'content/images/icons/add_24.png', | |
label: 'New', | |
enabled: true, // in all rows | |
fn: this.navigateToInsertView.bindDelegate(this) | |
}, | |
{ | |
id: 'open', | |
icon: '', | |
label: 'Open', | |
enabled: this.hasOpenProperty, // note: no bindDelegate as we want `this` to be the active view | |
fn: this.navigateToListView.bindDelegate(this, "Status eq 'Open'") | |
} | |
] | |
}); | |
}, | |
hasOpenProperty: function(action, selection) { | |
var listView = domAttr.get(selection.tag, 'data-key'); | |
var hasProp = viewFilters[listView]['open']; | |
// normally we would return here, but this adds a is-hidden CSS class that is: | |
// .is-hidden { display: none !important; } | |
// in my css file | |
domClass.toggle(this.actionsNode.childNodes[action.actionIndex], 'is-hidden', !hasProp); | |
return hasProp; | |
}, | |
navigateToInsertView: function(action, selection) { | |
var listView = domAttr.get(selection.tag, 'data-key'), | |
insertView = listView.split('_')[0] + '_edit', // this is a hack to change it from account_list to account_edit | |
view = App.getView(insertView); | |
if (view) | |
view.show({ | |
returnTo: listView, // after inserts it returns to the entity list, not home. | |
insert: true | |
}); | |
}, | |
navigateToListView: function(action, selection, whereClause) { | |
var listView = domAttr.get(selection.tag, 'data-key'), | |
view = App.getView(listView); | |
if (view) | |
view.show({ | |
query: whereClause // this is a pre-filter if the user does a search it will replace this clause | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment