Skip to content

Instantly share code, notes, and snippets.

@saintc0d3r
Last active December 25, 2015 12:19
Show Gist options
  • Save saintc0d3r/6975960 to your computer and use it in GitHub Desktop.
Save saintc0d3r/6975960 to your computer and use it in GitHub Desktop.
[Ext.js][ASP NET MVC] Simple SPA using Ext.js & ASP .NET MVC
Ext.application({
appFolder: '/Extjs/Application',
controllers: ['HomeController'],
name: AppNamespace,
launch: function() {
Ext.create('Ext.container.Viewport', {
layout: 'fit',
items: [{
xtype: 'specialOffers'
}]
});
}
});
Ext.define(AppNamespace + '.view.EditSpecialOffersDialog', {
extend: 'Ext.window.Window',
alias:'widget.editSpecialOffers',
title: '.:: Edit Special Offered Item ::.',
layout: 'fit',
width: 500,
autoShow: true,
initComponent: function() {
this.items = [{
xtype: 'form',
items: [{
xtype: 'textfield',
anchor: '100%',
name: 'Title',
fieldLabel: 'Name'
}, {
xtype: 'numberfield',
anchor: '100%',
name: 'Price',
fieldLabel: 'Price'
}]
}];
this.buttons = [{
text: 'save',
action: 'save'
}, {
text: 'cancel',
scope: this,
handler: this.close
}];
this.callParent(arguments);
}
});
Ext.define(AppNamespace + '.controller.HomeController', {
extend: 'Ext.app.Controller',
views: ['SpecialOffersView', 'EditSpecialOffersDialog'],
stores: ['SpecialOffersStore'],
models: ['SpecialOfferModel'],
init: function () {
this.control({
"specialOffers": {
celldblclick: function(tableview, td, cellIndex, record) {
var view = Ext.widget('editSpecialOffers');
view.down('form').loadRecord(record);
},
},
"editSpecialOffers button[action=save]": {
click: this.updateUser
}
});
},
updateUser: function (button) {
var dialog = button.up('window');
var form = dialog.down('form');
form.getRecord().set(form.getValues());
dialog.close();
}
});
@using System.Web.Optimization
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Xtreme Gaming Store</title>
<script src="~/Extjs/Application/Constants.js"></script>
<script src="~/Extjs/ext-all.js"></script>
<link rel="stylesheet" href="~/Extjs/Resources/css/ext-all.css">
</head>
<body>
<script src="/Extjs/Application/Application.js"></script>
</body>
</html>
using System.Collections.Generic;
using System.Web.Http;
using Xtreme.Gaming.Store.Domain.Services;
using Xtreme.Gaming.Store.Web.Spa.Models;
using Xtreme.Gaming.Store.Web.Spa.Models.Product;
namespace Xtreme.Gaming.Store.Web.Spa.Controllers
{
public class ProductController : ApiController
{
private readonly IProductService _productService;
public ProductController(IProductService productService)
{
_productService = productService;
}
//
// GET: /SpecialOffers
[AcceptVerbs("GET")]
public IEnumerable<SpecialOffer> SpecialOffers()
{
// Get a list of Products which are offered as current discounted items
var getSpecialOffersResponse = _productService.GetSpecialOffers();
return getSpecialOffersResponse.IsSuccess ? getSpecialOffersResponse.Products.AsSpecialOffers() : new SpecialOffer[0];
}
}
}
Ext.define(AppNamespace + '.model.SpecialOfferModel', {
extend: 'Ext.data.Model',
fields: [
{ name: 'Id', type: 'int' },
{ name: 'Title', type: 'string' },
{ name: 'Price', type: 'float' }
]
});
Ext.define(AppNamespace + '.store.SpecialOffersStore', {
extend: 'Ext.data.Store',
model: AppNamespace + '.model.SpecialOfferModel',
proxy: {
type: 'rest',
url: '/api/product/specialoffers',
reader: {
type: 'json',
idProperty: 'Id'
}
},
autoLoad: true
});
Ext.define(AppNamespace+ '.view.SpecialOffersView', {
extend: 'Ext.grid.Panel',
title: 'Special Offers',
alias: 'widget.specialOffers',
store: 'SpecialOffersStore',
initComponent: function () {
this.columns = [{ header: 'Name', dataIndex: 'Title', flex: 1 },
{ header: 'Price', dataIndex: 'Price', flex: 2 }];
this.callParent(arguments);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment