1+ @using BlogEngine .NET .Custom .Widgets
2+ @{
3+ // check if edit exists, no need to process
4+ if (Request .HttpMethod == " HEAD" ) { return ; }
5+
6+ var NumberOfLinks = 10 ;
7+ var TitleAdd = " " ;
8+ var LinkAdd = " " ;
9+ var targetNew = false ;
10+ var hdnId = " " ;
11+
12+ var widgetId = Request .QueryString [" id" ];
13+ var updateLink = BlogEngine .Core .Utils .RelativeOrAbsoluteWebRoot +
14+ " Custom/Widgets/LinkList/edit.cshtml?id=" + widgetId ;
15+ var settings = Common .GetSettings (widgetId );
16+ var linkList = new LinkList (widgetId );
17+
18+ Validation .Add (" txtNumberOfLinks" ,
19+ Validator .Required (" Field is required" ),
20+ Validator .Integer (" Field is numeric" )
21+ );
22+
23+ if (Request .Form [" btnAdd" ] != null || Request .Form [" btnUpdate" ] != null )
24+ {
25+ Validation .Add (" txtTitle" , Validator .Required (" Field is required" ));
26+ Validation .Add (" txtUrl" , Validator .Required (" Field is required" ));
27+ }
28+
29+ var delId = Request .QueryString [" delid" ];
30+ if (! string .IsNullOrEmpty (delId ))
31+ {
32+ linkList .RemoveLink (delId );
33+ }
34+ var editId = Request .QueryString [" editid" ];
35+ if (! string .IsNullOrEmpty (editId ))
36+ {
37+ var item = linkList .GetLinkById (editId );
38+ TitleAdd = item .Title ;
39+ LinkAdd = item .Url ;
40+ targetNew = item .Target == " on" ? true : false ;
41+ hdnId = item .Id ;
42+ }
43+
44+ if (IsPost )
45+ {
46+ if (Validation .IsValid ())
47+ {
48+ if (settings [" numberoflinks" ] != Request .Form [" txtNumberOfLinks" ])
49+ {
50+ settings [" numberoflinks" ] = Request .Form [" txtNumberOfLinks" ];
51+ Common .SaveSettings (settings , widgetId );
52+ }
53+ if (Request .Form [" btnAdd" ] != null )
54+ {
55+ linkList .SaveLink (" " , Request .Form [" txtTitle" ], Request .Form [" txtUrl" ], Request .Form [" cbTarget" ]);
56+ }
57+ if (! string .IsNullOrEmpty (Request .Form [" hdnId" ]))
58+ {
59+ linkList .SaveLink (Request .Form [" hdnId" ], Request .Form [" txtTitle" ], Request .Form [" txtUrl" ], Request .Form [" cbTarget" ]);
60+ }
61+ @: < script type = " text/javascript" > window .parent .toastr .success (" Completed" );< / script >
62+ }
63+ }
64+ if (settings != null && settings .Count > 0 )
65+ {
66+ NumberOfLinks = int .Parse (settings [" numberoflinks" ]);
67+ }
68+ var links = linkList .GetLinks ();
69+ }
70+ <!DOCTYPE html>
71+ <html >
72+ <head >
73+ <link rel =" stylesheet" href =" ~/Content/bootstrap.min.css" >
74+ <link rel =" stylesheet" href =" ~/Content/font-awesome.min.css" >
75+ <link rel =" stylesheet" href =" ~/admin/themes/standard/css/styles.css" >
76+ <style >
77+ body { background-color : #fff ; }
78+ .fa-times { color : #e45252 ; }
79+ .fa-pencil { color : #25811a ;}
80+ .links-row { margin : 20px 0 10px -15px ; padding-top : 10px ; border-top : 1px solid #ccc ; border-bottom : 1px solid #ccc ; }
81+ .field-validation-error { background-color : #d9534f ; border-color : #d9534f ; color : #fff ; padding : 5px 15px ; display : block ; }
82+ </style >
83+ </head >
84+ <body >
85+ <form id =" frmTitle" method =" post" onsubmit =" window.parent.updateTitle()" >
86+ <div class =" form-group" >
87+ <label >@Resources.labels.numberOfDisplayedItems </label >
88+ <input type =" text" class =" form-control" id =" txtNumberOfLinks" name =" txtNumberOfLinks" value =" @NumberOfLinks" />
89+ @Html.ValidationMessage( "txtNumberOfLinks")
90+ </div >
91+ <div >
92+ <button type =" submit" id =" btnSave" name =" btnSave" class =" btn btn-success btn-sm pull-left" >
93+ @Resources.labels.save
94+ </button >
95+ </div >
96+ <div class =" clearfix" >  ; </div >
97+ <div class =" row links-row" >
98+ <div class =" col-xs-6 col-md-6" >
99+ <div class =" form-content" >
100+ <div class =" form-group" >
101+ <label >@Resources.labels.title </label >
102+ <input type =" text" class =" form-control" id =" txtTitle" name =" txtTitle" value =" @TitleAdd" />
103+ @Html.ValidationMessage( "txtTitle")
104+ </div >
105+ <div class =" form-group" >
106+ @if (! string .IsNullOrEmpty (editId ))
107+ {
108+ <button type =" submit" id =" btnUpdate" name =" btnUpdate" formaction =" @updateLink" class =" btn btn-success btn-sm pull-left" >
109+ @Resources.labels.update
110+ </button >
111+ }
112+ else
113+ {
114+ <button type =" submit" id =" btnAdd" name =" btnAdd" class =" btn btn-success btn-sm pull-left" >
115+ @Resources.labels.addLink
116+ </button >
117+ }
118+ </div >
119+ </div >
120+ </div >
121+ <div class =" col-xs-6 col-md-6" >
122+ <div class =" form-content" >
123+ <div class =" form-group" >
124+ <label >@Resources.labels.websiteUrl </label >
125+ <input type =" text" class =" form-control" id =" txtUrl" name =" txtUrl" value =" @LinkAdd" />
126+ @Html.ValidationMessage( "txtUrl")
127+ </div >
128+ <div class =" form-group" >
129+ @Html.CheckBox( "cbTarget", targetNew) Open in new window
130+ </div >
131+ </div >
132+ </div >
133+ </div >
134+
135+ <table class =" table table-striped" >
136+ <thead >
137+ <tr >
138+ <th width =" 10%" >  ; </th >
139+ <th width =" 35%" >@Resources.labels.title </th >
140+ <th width =" 35%" >@Resources.labels.url </th >
141+ <th width =" 20%" >@Resources.labels.newWindow </th >
142+ </tr >
143+ </thead >
144+ <tbody >
145+ @foreach ( var link in links )
146+ {
147+ <tr >
148+ <td >
149+ <a href =" ?id=@widgetId&editid=@link.Id" title =" @Resources.labels.edit" ><i class =" fa fa-pencil" ></i ></a >   ;
150+ <a href =" ?id=@widgetId&delid=@link.Id" title =" @Resources.labels.delete" ><i class =" fa fa-times" ></i ></a >
151+ </td >
152+ <td >@link.Title </td >
153+ <td >@link.Url </td >
154+ <td >
155+ @if (link .Target == " on" )
156+ {
157+ <i class =" fa fa-check" ></i >
158+ }
159+ </td >
160+ </tr >
161+ }
162+ @if (links .Count == 0 )
163+ {
164+ <tr ><td colspan =" 4" >@Resources.labels.empty </td ></tr >
165+ }
166+ </tbody >
167+ </table >
168+ <input type =" hidden" id =" hdnId" name =" hdnId" value =" @hdnId" />
169+ </form >
170+ </body >
171+ </html >
0 commit comments