Created
April 29, 2014 20:03
-
-
Save zachelrath/0ed2282c821fc8171060 to your computer and use it in GitHub Desktop.
This file contains 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
<skuidpage showsidebar="true" showheader="true" tabtooverride="Opportunity"> | |
<models> | |
<model id="SortOrders" limit="100" query="true" createrowifnonefound="false" sobject="Sort_Order__c"> | |
<fields> | |
<field id="Sort_Order__c"/> | |
<field id="Skuid_Page__c"/> | |
<field id="Skuid_Page__r.Name"/> | |
<field id="Model_Id__c"/> | |
</fields> | |
<conditions> | |
<condition type="userinfo" value="" field="OwnerId" operator="=" enclosevalueinquotes="true" userinfotype="userid"/> | |
<condition type="fieldvalue" value="Opportunities_withSavedSortOrder" enclosevalueinquotes="true" field="Skuid_Page__r.Name"/> | |
</conditions> | |
</model> | |
<model id="Opportunity" limit="100" query="false" createrowifnonefound="false" sobject="Opportunity"> | |
<fields> | |
<field id="Name"/> | |
<field id="CreatedDate"/> | |
<field id="LeadSource"/> | |
<field id="StageName"/> | |
<field id="OwnerId"/> | |
<field id="Owner.Name"/> | |
</fields> | |
<conditions/> | |
</model> | |
</models> | |
<components> | |
<pagetitle model="Opportunity"> | |
<maintitle> | |
<template>{{Model.labelPlural}}</template> | |
</maintitle> | |
<subtitle> | |
<template>Home</template> | |
</subtitle> | |
<actions/> | |
</pagetitle> | |
<skootable showconditions="true" showsavecancel="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Opportunity" mode="read"> | |
<fields> | |
<field id="Name" allowordering="true"/> | |
<field id="LeadSource" allowordering="true"/> | |
<field id="StageName" allowordering="true"/> | |
<field id="OwnerId" allowordering="true"/> | |
<field id="CreatedDate" allowordering="true"/> | |
</fields> | |
<rowactions> | |
<action type="edit"/> | |
<action type="delete"/> | |
</rowactions> | |
<massactions usefirstitemasdefault="true"> | |
<action type="massupdate"/> | |
<action type="massdelete"/> | |
</massactions> | |
<views> | |
<view type="standard"/> | |
</views> | |
</skootable> | |
</components> | |
<resources> | |
<labels/> | |
<css/> | |
<javascript> | |
<jsitem location="inline" name="Load sort order" cachelocation="false" url="">(function(skuid){ | |
var $ = skuid.$; | |
$(function(){ | |
// Do NOT try to auto-sort these Models | |
var modelsToIgnore = { | |
}; | |
var SortOrders = skuid.model.getModel('SortOrders'); | |
modelsToIgnore[SortOrders.id]=1 | |
// See if we have a saved Sort Order for the Opportunity model | |
var modelsToLoad = [], | |
uniqueModelsToLoad = {}; | |
var GetSortOrderForModel = function(model){ | |
var target; | |
$.each(SortOrders.data,function(i,so){ | |
if (so.Model_Id__c===model.id) {target = so;return false;} | |
}); | |
if (!target){ | |
target = SortOrders.createRow(); | |
SortOrders.updateRow(target,{ | |
Model_Id__c: model.id, | |
Skuid_Page__c: skuid.page.id, | |
Sort_Order__c: model.orderByClause, | |
OwnerId: skuid.utils.userInfo.userId | |
}); | |
} | |
return target; | |
}; | |
if (SortOrders.data && SortOrders.data.length) { | |
$.each(SortOrders.data,function(i,so){ | |
var modelId = so.Model_Id__c; | |
if (modelId) { | |
var model = skuid.model.getModel(modelId); | |
if (model) { | |
console.log('found a corresponding Model, applying Sort Order') | |
// if we found a Model, apply our Sort Order to it | |
model.orderByClause = so.Sort_Order__c; | |
console.log('model order by clause: ' + model.orderByClause); | |
console.log('Sort Order: ' + so.Sort_Order__c); | |
if (modelId in uniqueModelsToLoad) {} | |
else { | |
modelsToLoad.push(model); | |
uniqueModelsToLoad[modelId]=model; | |
} | |
} | |
} | |
}); | |
} else { | |
// Create a default Sort Order for all Models | |
// NOT being sorted by our saved sorts | |
$.each(skuid.model.list(),function(i,model){ | |
var modelId = model.id; | |
if (modelId in uniqueModelsToLoad) return true; | |
else { | |
if (model.orderByClause) { | |
GetSortOrderForModel(model); | |
} | |
// Add this Model to the list of Models to load, | |
// if it does not yet have any data in it | |
if (model.data.length===0 && !(modelId in modelsToIgnore)){ | |
modelsToLoad.push(model); | |
} | |
} | |
}); | |
} | |
if (modelsToLoad.length) { | |
skuid.model.updateData(modelsToLoad); | |
} | |
// NOW, setup some listeners on all our Models | |
// so that whenever they are updated, | |
// we save our Sort Orders. | |
skuid.events.subscribe('models.loaded',function(loadResult){ | |
$.each(loadResult.models,function(modelId,model){ | |
if (model.orderByClause){ | |
var so = GetSortOrderForModel(model); | |
SortOrders.updateRow(so,'Sort_Order__c',model.orderByClause); | |
} | |
}); | |
SortOrders.save(); | |
}); | |
}); | |
})(skuid);</jsitem> | |
</javascript> | |
</resources> | |
</skuidpage> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment