From 4b7605212e2b32d2a80effda21124f1257d4fdc6 Mon Sep 17 00:00:00 2001 From: Will Marshall Date: Wed, 18 Dec 2013 14:45:32 +1100 Subject: [PATCH] Adding text trunctation in Angular --- app/assets/javascripts/darkswarm/shop.js.coffee | 13 ++++++++++++- app/views/shop/_products.html.haml | 2 +- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/darkswarm/shop.js.coffee b/app/assets/javascripts/darkswarm/shop.js.coffee index faffd0e6c4..3b30e222d6 100644 --- a/app/assets/javascripts/darkswarm/shop.js.coffee +++ b/app/assets/javascripts/darkswarm/shop.js.coffee @@ -1,2 +1,13 @@ -window.Shop = angular.module("Shop", ["ngResource"]).config ($httpProvider) -> +window.Shop = angular.module("Shop", ["ngResource", "filters"]).config ($httpProvider) -> $httpProvider.defaults.headers.post['X-CSRF-Token'] = $('meta[name="csrf-token"]').attr('content') + +#angular.module('Shop', ['filters']) + +angular.module("filters", []).filter "truncate", -> + (text, length, end) -> + length = 10 if isNaN(length) + end = "..." if end is `undefined` + if text.length <= length or text.length - end.length <= length + text + else + String(text).substring(0, length - end.length) + end diff --git a/app/views/shop/_products.html.haml b/app/views/shop/_products.html.haml index c8fe15ed3f..a8218af7dd 100644 --- a/app/views/shop/_products.html.haml +++ b/app/views/shop/_products.html.haml @@ -18,7 +18,7 @@ %h5 {{ product.name }} {{ product.supplier.name }} - %td {{ product.description }} + %td {{ product.description | truncate:250 }} %td {{ product.master.options_text }} %td %input{type: :number, value: 0, min: 0, name: "quantity_variant_{{product.master.id}}"}