Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
scottdurow committed Sep 19, 2016
2 parents a7162a6 + 14c12c4 commit 87b9cdf
Show file tree
Hide file tree
Showing 14 changed files with 433 additions and 86 deletions.
3 changes: 3 additions & 0 deletions SparkleXrmSource/Client/ContactEditor/Model/Entities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ public Contact()
[ScriptName("ownerid")]
public EntityReference OwnerId;

[ScriptName("parentcustomerid")]
public EntityReference ParentCustomerId;

}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using SparkleXrm;
using Client.ContactEditor.ViewModels;
using Client.ContactEditor.Model;
using Xrm;
using System.Runtime.CompilerServices;

namespace Client.ContactEditor.ViewModels
{
Expand Down Expand Up @@ -229,7 +231,6 @@ public Action SaveCommand()
public void TransactionCurrencySearchCommand(string term, Action<EntityCollection> callback)
{
// Get the option set values

string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='transactioncurrency'>
<attribute name='transactioncurrencyid' />
Expand All @@ -255,6 +256,14 @@ public void TransactionCurrencySearchCommand(string term, Action<EntityCollectio

});
}
[PreserveCase]
public void AddNewAccountInLine(object item)
{
OpenEntityFormOptions newRecordOptions = new OpenEntityFormOptions();
newRecordOptions.OpenInNewWindow = true;
Utility.OpenEntityForm2("account", null, null, newRecordOptions);

}
public void OwnerSearchCommand(string term, Action<EntityCollection> callback)
{

Expand Down Expand Up @@ -287,6 +296,29 @@ public void OwnerSearchCommand(string term, Action<EntityCollection> callback)
}
}

[PreserveCase]
public void AccountSearchCommand(string term, Action<EntityCollection> callback)
{
string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
<entity name='account'>
<attribute name='accountid' />
<attribute name='name' />
<attribute name='address1_city' />
<order attribute='name' descending='false' />
<filter type='and'>
<condition attribute='name' operator='like' value='%{0}%' />
</filter>
</entity>
</fetch>";

fetchXml = string.Format(fetchXml, XmlHelper.Encode(term));
OrganizationServiceProxy.BeginRetrieveMultiple(fetchXml, delegate(object result)
{
EntityCollection fetchResult = OrganizationServiceProxy.EndRetrieveMultiple(result, typeof(Entity));
callback(fetchResult);
});
}

private void SearchRecords(string term, Action<EntityCollection> callback, string entityType, string entityNameAttribute)
{
string fetchXml = @"<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true' count='25'>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ public partial class ObservableContact
[ScriptName("transactioncurrencyid")]
public Observable<EntityReference> TransactionCurrencyId = Knockout.Observable<EntityReference>();

[ScriptName("parentcustomerid")]
public Observable<EntityReference> ParentCustomerId = Knockout.Observable<EntityReference>();

[ScriptName("creditlimit")]
public Observable<Money> CreditLimit = Knockout.Observable<Money>();

Expand All @@ -53,6 +56,7 @@ public void SetValue(Contact value)
AccountRoleCode.SetValue(_value.AccountRoleCode.Value);
NumberOfChildren.SetValue(_value.NumberOfChildren.Value);
TransactionCurrencyId.SetValue(_value.TransactionCurrencyId);
ParentCustomerId.SetValue(_value.ParentCustomerId);
CreditLimit.SetValue(_value.CreditLimit);
}

Expand All @@ -67,6 +71,7 @@ public Contact Commit()
_value.TransactionCurrencyId = TransactionCurrencyId.GetValue();
_value.CreditLimit = CreditLimit.GetValue();
_value.EntityState = EntityStates.Changed;
_value.ParentCustomerId = ParentCustomerId.GetValue();
return _value;
}

Expand Down
28 changes: 15 additions & 13 deletions SparkleXrmSource/Client/ContactEditor/Views/ContactEditorView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using SparkleXrm.CustomBinding;
using Client.ContactEditor.ViewModels;
using Xrm;
using Client.ContactEditor.Model;

namespace Client.Views
{
Expand All @@ -36,7 +37,7 @@ public static void init()

OrganizationServiceProxy.GetUserSettings();
// Data Bind Grid
List<Column> columns = GridDataViewBinder.ParseLayout(",entityState,20,First Name,firstname,200,Last Name,lastname,200,Birth Date,birthdate,200,Account Role Code,accountrolecode,200,Number of Children,numberofchildren,100,Currency,transactioncurrencyid,200,Credit Limit,creditlimit,100,Gender,gendercode,100,Owner,ownerid,100");
List<Column> columns = GridDataViewBinder.ParseLayout(",entityState,20,First Name,firstname,200,Last Name,lastname,200,Birth Date,birthdate,200,Account Role Code,accountrolecode,200,Number of Children,numberofchildren,100,Currency,transactioncurrencyid,200,Credit Limit,creditlimit,100,Gender,gendercode,100,Owner,ownerid,100,Parent Customer,parentcustomerid,100");

// Set Column formatters and editors
columns[0].Formatter = delegate(int row, int cell, object value, Column columnDef, object dataContext)
Expand Down Expand Up @@ -65,21 +66,30 @@ public static void init()

// Currency Column
XrmLookupEditor.BindColumn(columns[6], vm.TransactionCurrencySearchCommand, "transactioncurrencyid", "currencyname", "");

// Credit Limit Column
XrmMoneyEditor.BindColumn(columns[7], -10000, 10000);

// Another optionset
XrmOptionSetEditor.BindColumn(columns[8], "contact", columns[8].Field, true);

// Owner Column
XrmLookupEditorOptions options = (XrmLookupEditorOptions)XrmLookupEditor.BindColumn(columns[9], vm.OwnerSearchCommand, "id", "name", "").Options;
options.showFooter = true;


// OWner Column
XrmLookupEditor.BindColumn(columns[9], vm.OwnerSearchCommand, "id", "name", "");
// Account Column
XrmLookupEditorOptions accountLookupOptions = (XrmLookupEditorOptions)XrmLookupEditor.BindColumn(columns[10], vm.AccountSearchCommand, "id", "name", "").Options;
accountLookupOptions.showFooter = true;
accountLookupOptions.footerButton = new XrmLookupEditorButton();
accountLookupOptions.footerButton.Label = "Add New";
accountLookupOptions.footerButton.Image = "/_imgs/add_10.png";
accountLookupOptions.footerButton.OnClick = vm.AddNewAccountInLine;

// Create Grid
GridDataViewBinder contactGridDataBinder = new GridDataViewBinder();
Grid contactsGrid = contactGridDataBinder.DataBindXrmGrid(vm.Contacts, columns, "container", "pager",true,false);
//contactGridDataBinder.BindClickHandler(contactsGrid);

// Data Bind
ViewBase.RegisterViewModel(vm);

Expand All @@ -89,13 +99,5 @@ public static void init()
}, 0);

}








}
}
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,31 @@ TEXTAREA.sparkle-Input {
width:150px;
text-overflow:ellipsis;
}

.sparkle-menu-footer {
position: absolute;
border-width: 1px;
border-style: solid;
border-color: rgb(160, 160, 160) rgb(128, 128, 128) rgb(128, 128, 128);
margin: 0px;
padding: 2px;
display: block;
background: white;
height: 16px;
min-width: 100px;
}
.sparkle-xrm .ui-autocomplete {
min-width:100px !important;
}
.sparkle-menu-footer-right {
position: absolute;
right: 4px;
top: 1px;
}
.sparkle-menu-footer-left {
position: absolute;
left: 4px;
top: 1px;
}
.sparkle-menu-item-label {
}

Expand Down Expand Up @@ -1030,7 +1054,6 @@ TEXTAREA.sparkle-Input {
width: 16px;
height: 16px;
overflow: hidden;
display:block;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ <h2 class="sparkle-Form">
</table>
<!--/ko-->
<!--ko if:type=='lookup'-->
<table style="width: 100%" cellspacing="0" cellpadding="0" class="sparkle-control-layout-table" data-bind="lookup: field, queryCommand: queryCommand, typeCodeAttribute: typeCodeAttribute, idAttribute: idAttribute, nameAttribute: nameAttribute, visible: visible">
<table style="width: 100%" cellspacing="0" cellpadding="0" class="sparkle-control-layout-table" data-bind="lookup: field, queryCommand: queryCommand, typeCodeAttribute: typeCodeAttribute, idAttribute: idAttribute, nameAttribute: nameAttribute, visible: visible, footerButton: $data.footerButton, showFooter: $data.showFooter">
<tr>
<td class="sparkle-input-Container">
<input data-bind="disable: disable" type="text" class="sparkle-Input sparkle-Text sparkle-input-lookup-part" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,48 @@
<!--/ko-->
</tr>
<tr valign="top">
<!--ko template: { name: 'sparkle-form-field', data: { label: 'Currency',field:transactioncurrencyid,required:0,type:'lookup',disable:false,visible:true,queryCommand: $root.transactionCurrencySearchCommand,type:'lookup',typeCodeAttribute: '', idAttribute:'transactioncurrencyid',nameAttribute:'currencyname' } }-->
<!--ko template: { name: 'sparkle-form-field',
data: {
label: 'Currency',
field:transactioncurrencyid,
required:0,
type:'lookup',
disable:false,
visible:true,
queryCommand: $root.transactionCurrencySearchCommand,
type:'lookup',
typeCodeAttribute: '',
idAttribute:'transactioncurrencyid',
nameAttribute:'currencyname,currencysymbol',
showFooter: true
}
}-->
<!--/ko-->
</tr>
<tr valign="top">
<!--ko template: { name: 'sparkle-form-field', data: { label: 'Credit Limit',field:creditlimit,required:0,type:'money',disable:false,visible:true,minvalue:0,maxvalue:100000000 } }-->
<!--/ko-->
</tr>
<tr valign="top">
<!--ko template: { name: 'sparkle-form-field',
data: {
label: 'Account',
field:parentcustomerid,
required:0,
type:'lookup',
disable:false,
visible:true,
queryCommand: $root.AccountSearchCommand,
type:'lookup',
typeCodeAttribute: '',
idAttribute:'accountid',
nameAttribute:'name,address1_city',
showFooter: true,
footerButton: {label:'Add New',onClick:$root.AddNewAccountInLine, image:'/_imgs/add_10.png' }
}
}-->
<!--/ko-->
</tr>
</table>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,31 @@ TEXTAREA.sparkle-Input {
width:150px;
text-overflow:ellipsis;
}

.sparkle-menu-footer {
position: absolute;
border-width: 1px;
border-style: solid;
border-color: rgb(160, 160, 160) rgb(128, 128, 128) rgb(128, 128, 128);
margin: 0px;
padding: 2px;
display: block;
background: white;
height: 16px;
min-width: 100px;
}
.sparkle-xrm .ui-autocomplete {
min-width:100px !important;
}
.sparkle-menu-footer-right {
position: absolute;
right: 4px;
top: 1px;
}
.sparkle-menu-footer-left {
position: absolute;
left: 4px;
top: 1px;
}
.sparkle-menu-item-label {
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ <h2 class="sparkle-Form">
</table>
<!--/ko-->
<!--ko if:type=='lookup'-->
<table style="width: 100%" cellspacing="0" cellpadding="0" class="sparkle-control-layout-table" data-bind="lookup: field, queryCommand: queryCommand, typeCodeAttribute: typeCodeAttribute, idAttribute: idAttribute, nameAttribute: nameAttribute, visible: visible">
<table style="width: 100%" cellspacing="0" cellpadding="0" class="sparkle-control-layout-table" data-bind="lookup: field, queryCommand: queryCommand, typeCodeAttribute: typeCodeAttribute, idAttribute: idAttribute, nameAttribute: nameAttribute, visible: visible, footerButton: $data.footerButton, showFooter: $data.showFooter">
<tr>
<td class="sparkle-input-Container">
<input data-bind="disable: disable" type="text" class="sparkle-Input sparkle-Text sparkle-input-lookup-part" />
Expand Down
8 changes: 6 additions & 2 deletions SparkleXrmSource/SparkleXrm/Sdk/Entity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public static int SortDelegate(string attributeName, Entity a, Entity b)
typeName = l.GetType().Name;
else if (r != null)
typeName = r.GetType().Name;

if (l != r)
{
switch (typeName.ToLowerCase())
Expand All @@ -240,7 +240,11 @@ public static int SortDelegate(string attributeName, Entity a, Entity b)
result = 1;
break;
case "date":
if ((bool)Script.Literal("{0}<{1}", l, r))
if (l == null)
result = -1;
else if (r == null)
result = 1;
else if ((bool)Script.Literal("{0}<{1}", l, r))
result = -1;
else
result = 1;
Expand Down
Loading

0 comments on commit 87b9cdf

Please sign in to comment.