11using System ;
2+ using System . Collections . Generic ;
23using System . IO ;
34using System . Linq ;
45using System . Text ;
2122namespace Nop . Admin . Controllers
2223{
2324 public partial class LanguageController : BaseAdminController
24- {
25- #region Fields
25+ {
26+ #region Fields
2627
2728 private readonly ILanguageService _languageService ;
2829 private readonly ILocalizationService _localizationService ;
@@ -39,12 +40,12 @@ public partial class LanguageController : BaseAdminController
3940 public LanguageController ( ILanguageService languageService ,
4041 ILocalizationService localizationService ,
4142 ICurrencyService currencyService ,
42- IStoreService storeService ,
43+ IStoreService storeService ,
4344 IStoreMappingService storeMappingService ,
4445 IPermissionService permissionService ,
4546 ICustomerActivityService customerActivityService )
4647 {
47- this . _localizationService = localizationService ;
48+ this . _localizationService = localizationService ;
4849 this . _languageService = languageService ;
4950 this . _currencyService = currencyService ;
5051 this . _storeService = storeService ;
@@ -53,22 +54,10 @@ public LanguageController(ILanguageService languageService,
5354 this . _customerActivityService = customerActivityService ;
5455 }
5556
56- #endregion
57+ #endregion
5758
5859 #region Utilities
5960
60- [ NonAction ]
61- protected virtual void PrepareFlagsModel ( LanguageModel model )
62- {
63- if ( model == null )
64- throw new ArgumentNullException ( "model" ) ;
65-
66- model . FlagFileNames = Directory
67- . EnumerateFiles ( CommonHelper . MapPath ( "~/Content/Images/flags/" ) , "*.png" , SearchOption . TopDirectoryOnly )
68- . Select ( Path . GetFileName )
69- . ToList ( ) ;
70- }
71-
7261 [ NonAction ]
7362 protected virtual void PrepareStoresMappingModel ( LanguageModel model , Language language , bool excludeProperties )
7463 {
@@ -98,10 +87,10 @@ protected virtual void PrepareCurrenciesModel(LanguageModel model)
9887
9988 //templates
10089 model . AvailableCurrencies . Add ( new SelectListItem
101- {
102- Text = "---" ,
103- Value = "0"
104- } ) ;
90+ {
91+ Text = "---" ,
92+ Value = "0"
93+ } ) ;
10594 var currencies = _currencyService . GetAllCurrencies ( true ) ;
10695 foreach ( var currency in currencies )
10796 {
@@ -147,32 +136,32 @@ public ActionResult Index()
147136 return RedirectToAction ( "List" ) ;
148137 }
149138
150- public ActionResult List ( )
139+ public ActionResult List ( )
151140 {
152141 if ( ! _permissionService . Authorize ( StandardPermissionProvider . ManageLanguages ) )
153142 return AccessDeniedView ( ) ;
154143
155- return View ( ) ;
156- }
144+ return View ( ) ;
145+ }
157146
158- [ HttpPost ]
147+ [ HttpPost ]
159148 public ActionResult List ( DataSourceRequest command )
160149 {
161150 if ( ! _permissionService . Authorize ( StandardPermissionProvider . ManageLanguages ) )
162151 return AccessDeniedView ( ) ;
163152
164- var languages = _languageService . GetAllLanguages ( true ) ;
165- var gridModel = new DataSourceResult
166- {
167- Data = languages . Select ( x => x . ToModel ( ) ) ,
168- Total = languages . Count ( )
169- } ;
170- return new JsonResult
171- {
172- Data = gridModel
173- } ;
174- }
175-
153+ var languages = _languageService . GetAllLanguages ( true ) ;
154+ var gridModel = new DataSourceResult
155+ {
156+ Data = languages . Select ( x => x . ToModel ( ) ) ,
157+ Total = languages . Count ( )
158+ } ;
159+ return new JsonResult
160+ {
161+ Data = gridModel
162+ } ;
163+ }
164+
176165 public ActionResult Create ( )
177166 {
178167 if ( ! _permissionService . Authorize ( StandardPermissionProvider . ManageLanguages ) )
@@ -183,8 +172,6 @@ public ActionResult Create()
183172 PrepareStoresMappingModel ( model , null , false ) ;
184173 //currencies
185174 PrepareCurrenciesModel ( model ) ;
186- //flags
187- PrepareFlagsModel ( model ) ;
188175 //default values
189176 model . Published = true ;
190177 return View ( model ) ;
@@ -225,38 +212,34 @@ public ActionResult Create(LanguageModel model, bool continueEditing)
225212 PrepareStoresMappingModel ( model , null , true ) ;
226213 //currencies
227214 PrepareCurrenciesModel ( model ) ;
228- //flags
229- PrepareFlagsModel ( model ) ;
230215
231216 return View ( model ) ;
232217 }
233218
234- public ActionResult Edit ( int id )
219+ public ActionResult Edit ( int id )
235220 {
236221 if ( ! _permissionService . Authorize ( StandardPermissionProvider . ManageLanguages ) )
237222 return AccessDeniedView ( ) ;
238223
239- var language = _languageService . GetLanguageById ( id ) ;
224+ var language = _languageService . GetLanguageById ( id ) ;
240225 if ( language == null )
241226 //No language found with the specified id
242227 return RedirectToAction ( "List" ) ;
243228
244229 //set page timeout to 5 minutes
245230 this . Server . ScriptTimeout = 300 ;
246231
247- var model = language . ToModel ( ) ;
232+ var model = language . ToModel ( ) ;
248233 //Stores
249234 PrepareStoresMappingModel ( model , language , false ) ;
250235 //currencies
251236 PrepareCurrenciesModel ( model ) ;
252- //flags
253- PrepareFlagsModel ( model ) ;
254237
255238 return View ( model ) ;
256- }
239+ }
257240
258241 [ HttpPost , ParameterBasedOnFormName ( "save-continue" , "continueEditing" ) ]
259- public ActionResult Edit ( LanguageModel model , bool continueEditing )
242+ public ActionResult Edit ( LanguageModel model , bool continueEditing )
260243 {
261244 if ( ! _permissionService . Authorize ( StandardPermissionProvider . ManageLanguages ) )
262245 return AccessDeniedView ( ) ;
@@ -294,7 +277,7 @@ public ActionResult Edit(LanguageModel model, bool continueEditing)
294277 //selected tab
295278 SaveSelectedTabName ( ) ;
296279
297- return RedirectToAction ( "Edit" , new { id = language . Id } ) ;
280+ return RedirectToAction ( "Edit" , new { id = language . Id } ) ;
298281 }
299282 return RedirectToAction ( "List" ) ;
300283 }
@@ -305,11 +288,9 @@ public ActionResult Edit(LanguageModel model, bool continueEditing)
305288 PrepareStoresMappingModel ( model , language , true ) ;
306289 //currencies
307290 PrepareCurrenciesModel ( model ) ;
308- //flags
309- PrepareFlagsModel ( model ) ;
310291
311292 return View ( model ) ;
312- }
293+ }
313294
314295 [ HttpPost ]
315296 public ActionResult Delete ( int id )
@@ -329,7 +310,7 @@ public ActionResult Delete(int id)
329310 ErrorNotification ( _localizationService . GetResource ( "Admin.Configuration.Languages.PublishedLanguageRequired" ) ) ;
330311 return RedirectToAction ( "Edit" , new { id = language . Id } ) ;
331312 }
332-
313+
333314 //delete
334315 _languageService . DeleteLanguage ( language ) ;
335316
@@ -341,15 +322,35 @@ public ActionResult Delete(int id)
341322 return RedirectToAction ( "List" ) ;
342323 }
343324
344- #endregion
325+ [ HttpPost ]
326+ public JsonResult GetAvailableFlagFileNames ( )
327+ {
328+ if ( ! _permissionService . Authorize ( StandardPermissionProvider . ManageLanguages ) )
329+ return Json ( "Access denied" ) ;
330+
331+ var flagNames = Directory
332+ . EnumerateFiles ( CommonHelper . MapPath ( "~/Content/Images/flags/" ) , "*.png" , SearchOption . TopDirectoryOnly )
333+ . Select ( Path . GetFileName )
334+ . ToList ( ) ;
335+
336+ var availableFlagFileNames = flagNames . Select ( flagName => new SelectListItem
337+ {
338+ Text = flagName ,
339+ Value = flagName
340+ } ) . ToList ( ) ;
341+
342+ return Json ( availableFlagFileNames ) ;
343+ }
344+
345+ #endregion
346+
347+ #region Resources
345348
346- #region Resources
347-
348349 [ HttpPost ]
349350 //do not validate request token (XSRF)
350351 //for some reasons it does not work with "filtering" support
351- [ AdminAntiForgery ( true ) ]
352- public ActionResult Resources ( int languageId , DataSourceRequest command , LanguageResourcesListModel model )
352+ [ AdminAntiForgery ( true ) ]
353+ public ActionResult Resources ( int languageId , DataSourceRequest command , LanguageResourcesListModel model )
353354 {
354355 if ( ! _permissionService . Authorize ( StandardPermissionProvider . ManageLanguages ) )
355356 return AccessDeniedView ( ) ;
@@ -366,21 +367,21 @@ public ActionResult Resources(int languageId, DataSourceRequest command, Languag
366367
367368 var resources = query
368369 . Select ( x => new LanguageResourceModel
369- {
370- LanguageId = languageId ,
371- Id = x . Value . Key ,
372- Name = x . Key ,
373- Value = x . Value . Value ,
374- } ) ;
375-
370+ {
371+ LanguageId = languageId ,
372+ Id = x . Value . Key ,
373+ Name = x . Key ,
374+ Value = x . Value . Value ,
375+ } ) ;
376+
376377 var gridModel = new DataSourceResult
377378 {
378379 Data = resources . PagedForCommand ( command ) ,
379380 Total = resources . Count ( )
380381 } ;
381382
382383 return Json ( gridModel ) ;
383- }
384+ }
384385
385386 [ HttpPost ]
386387 public ActionResult ResourceUpdate ( LanguageResourceModel model )
@@ -447,7 +448,7 @@ public ActionResult ResourceAdd(int languageId, [Bind(Exclude = "Id")] LanguageR
447448
448449 return new NullJsonResult ( ) ;
449450 }
450-
451+
451452 [ HttpPost ]
452453 public ActionResult ResourceDelete ( int id )
453454 {
@@ -463,7 +464,7 @@ public ActionResult ResourceDelete(int id)
463464 }
464465
465466 #endregion
466-
467+
467468 #region Export / Import
468469
469470 public ActionResult ExportXml ( int id )
0 commit comments