PageRenderTime 14ms CodeModel.GetById 1ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/BlogEngine/BlogEngine.NET/admin/Posts/Add_entry.aspx

#
ASP.NET | 318 lines | 294 code | 24 blank | 0 comment | 17 complexity | b2c99143a8d666e19907521865a20487 MD5 | raw file
  1<%@ Page Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true"
  2    CodeFile="Add_entry.aspx.cs" Inherits="Admin.Posts.AddEntry" ValidateRequest="False"
  3    EnableSessionState="True" %>
  4
  5<%@ Register Src="~/admin/htmlEditor.ascx" TagPrefix="Blog" TagName="TextEditor" %>
  6<%@ Register src="Menu.ascx" tagname="TabMenu" tagprefix="menu" %>
  7<%@ Register Src="~/admin/FileManager/FileManager.ascx" TagName="FileManager" TagPrefix="con" %>
  8<asp:Content ID="Content1" ContentPlaceHolderID="cphAdmin" runat="Server">
  9	<div class="content-box-outer">
 10        <con:FileManager runat="server" ID="FileManager1" />
 11		<div class="content-box-full">
 12            <h1><%=Resources.labels.addEditPost %></h1>
 13            <script type="text/javascript">
 14                function GetSlug() {
 15                    var title = document.getElementById('<%=txtTitle.ClientID %>').value;
 16                    WebForm_DoCallback('__Page', title, ApplySlug, 'slug', null, false)
 17                }
 18
 19                function ApplySlug(arg, context) {
 20                    var slug = document.getElementById('<%=txtSlug.ClientID %>');
 21                    slug.value = arg;
 22                }
 23
 24                function AutoSave() {
 25                    var content = document.getElementById('<%=txtRawContent.ClientID %>') != null ? document.getElementById('<%=txtRawContent.ClientID %>').value : tinyMCE.activeEditor.getContent();
 26                    var title = document.getElementById('<%=txtTitle.ClientID %>').value;
 27                    var desc = document.getElementById('<%=txtDescription.ClientID %>').value;
 28                    var slug = document.getElementById('<%=txtSlug.ClientID %>').value;
 29                    var tags = document.getElementById('<%=txtTags.ClientID %>').value;
 30                    var s = ';|;';
 31                    var post = content + s + title + s + desc + s + slug + s + tags;
 32
 33                    if (content.length > 10) {
 34                        WebForm_DoCallback('__Page', '_autosave' + post, null, 'autosave', null, false);
 35                    }
 36
 37                    setTimeout("AutoSave()", 5000);
 38
 39                    var currentDate = new Date()
 40                    document.getElementById('autoSaveLabel').innerHTML = "Autosaved on " + currentDate;
 41                }
 42
 43                document.body.onkeypress = ESCclose;
 44
 45                function ESCclose(evt) {
 46                    if (!evt)
 47                        evt = window.event;
 48
 49                    if (evt.keyCode == 27)
 50                        document.getElementById('tagselector').style.display = 'none';
 51                }
 52
 53                function AddTag(element) {
 54                    var input = document.getElementById('<%=txtTags.ClientID %>');
 55                    input.value += element.innerHTML + ', ';
 56                }
 57
 58                function ToggleTagSelector() {
 59                    var element = document.getElementById('tagselector');
 60                    if (element.style.display == "none")
 61                        element.style.display = "block";
 62                    else
 63                        element.style.display = "none";
 64                }
 65                function toggleAutomaticDate() {
 66                    var element = document.getElementById('rbtManual');
 67                    var panel = document.getElementById('datePanel');
 68                    if (element.checked) {
 69                        panel.style.display = "block";
 70                    }
 71                    else {
 72                        panel.style.display = "none";
 73                    }
 74                }
 75                function SavePost() {
 76                    $('.loader').show();
 77
 78                    var content = document.getElementById('<%=txtRawContent.ClientID %>') != null ? document.getElementById('<%=txtRawContent.ClientID %>').value : tinyMCE.activeEditor.getContent();
 79
 80                    var title = document.getElementById('<%=txtTitle.ClientID %>').value;
 81                    var desc = document.getElementById('<%=txtDescription.ClientID %>').value;
 82                    var slug = document.getElementById('<%=txtSlug.ClientID %>').value;
 83                    var tags = document.getElementById('<%=txtTags.ClientID %>').value;
 84                    
 85                    var author = $("[id$='ddlAuthor'] option:selected").val();
 86                    var isPublished = $("[id$='cbPublish']").is(':checked');
 87                    var hasCommentsEnabled = $("[id$='cbEnableComments']").is(':checked');
 88
 89                    var cats = "";
 90                    var checkedCats = $('.cblCategories input[@type=checkbox]:checked');
 91                    if (checkedCats.length > 0) {
 92                        checkedCats.each(function () {
 93                            var jThis = $(this);
 94                            cats += jThis.attr("id") + ",";
 95                        });
 96                    }
 97
 98                    var date = document.getElementById('<%=txtDate.ClientID %>').value;
 99                    var time = document.getElementById('<%=txtTime.ClientID %>').value;
100
101                    var dto = {
102                        "id": Querystring('id'),
103                        "content": content,
104                        "title": title,
105                        "desc": desc,
106                        "slug": slug,
107                        "tags": tags,
108                        "author": author,
109                        "isPublished": isPublished,
110                        "hasCommentsEnabled": hasCommentsEnabled,
111                        "cats": cats,
112                        "date": date,
113                        "time": time
114                    };
115
116                    //alert(JSON.stringify(dto));
117
118                    $.ajax({
119                        url: SiteVars.ApplicationRelativeWebRoot + "admin/AjaxHelper.aspx/SavePost",
120                        type: "POST",
121                        dataType: "json",
122                        contentType: "application/json; charset=utf-8",
123                        data: JSON.stringify(dto),
124                        beforeSend: onAjaxBeforeSend,
125                        success: function (result) {
126                            var rt = result.d;
127                            if (rt.Success) {
128                                if (rt.Data) {
129                                    window.location.href = rt.Data;
130                                } else {
131                                    ShowStatus("success", rt.Message);
132                                }
133                            }
134                            else
135                                ShowStatus("warning", rt.Message);
136                        }
137                    });
138
139                    $('.loader').hide();
140                    return false;
141                }
142            </script>
143            <script type="text/javascript" src="../jquery.colorbox.js"></script>
144            <script type="text/javascript">
145                $(document).ready(function () {
146                	$("#uploadImage").colorbox({ width: "550px", inline: true, href: "#uploadImagePanel" });
147                	$("#uploadVideo").colorbox({ width: "550px", inline: true, href: "#uploadVideoPanel" });
148                    $("#uploadFile").colorbox({ width: "550px", inline: true, href: "#uploadFilePanel" });
149                });
150
151                function closeOverlay() {
152                    $.colorbox.close();
153                    return false;
154                }
155            </script>
156
157            <div runat="server" style="visibility:hidden;height:1px">
158                <div id="uploadVideoPanel" class="overlaypanel">
159                    <h2><%=Resources.labels.insertVideo %></h2>
160                    <ul class="fl" style="margin:0;">
161                        <li>
162                            <asp:Label ID="lblVideoUpload" CssClass="lbl" AssociatedControlID="txtUploadVideo" runat="server" Text='<%$ Resources:labels, uploadVideo %>' />
163                            <asp:FileUpload runat="server" ID="txtUploadVideo" Width="400" size="50" ValidationGroup="imageupload" />
164                            <asp:RequiredFieldValidator ID="txtUploadVideoValidator" runat="Server" ControlToValidate="txtUploadVideo" ErrorMessage="<%$ Resources:labels, required %>"
165                                ValidationGroup="videoupload" />
166                        </li>
167                        <li style="margin:0;">
168                            <asp:Button runat="server" ID="btnUploadVideo" Text="<%$Resources:labels,upload %>"
169                                ValidationGroup="videoupload" CssClass="btn primary" OnClientClick="colorboxDialogSubmitClicked('videoupload', 'uploadVideoPanel');" /> <%=Resources.labels.or %> <a href="#" onclick="return closeOverlay();"><%=Resources.labels.cancel %></a>
170                        </li>
171                    </ul>
172                </div>
173                <div id="uploadImagePanel" class="overlaypanel">
174                    <h2><%=Resources.labels.insertImage %></h2>
175                    <ul class="fl" style="margin:0;">
176                        <li>
177                            <asp:Label ID="lblFileUpload" CssClass="lbl" AssociatedControlID="txtUploadImage" runat="server" Text='<%$ Resources:labels, uploadImage %>' />
178                            <asp:FileUpload runat="server" ID="txtUploadImage" Width="400" size="50" ValidationGroup="imageupload" />
179                            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="Server" ControlToValidate="txtUploadImage" ErrorMessage="<%$ Resources:labels, required %>"
180                                ValidationGroup="imageupload" />
181                        </li>
182                        <li style="margin:0;">
183                            <asp:Button runat="server" ID="btnUploadImage" Text="<%$Resources:labels,upload %>"
184                                ValidationGroup="imageupload" CssClass="btn primary" OnClientClick="colorboxDialogSubmitClicked('imageupload', 'uploadImagePanel');" /> <%=Resources.labels.or %> <a href="#" onclick="return closeOverlay();"><%=Resources.labels.cancel %></a>
185                        </li>
186                    </ul>
187                </div>
188                <div id="uploadFilePanel" class="overlaypanel">
189                    <h2><%=Resources.labels.attachFile %></h2>
190                    <ul class="fl" style="margin:0;">
191                        <li>
192                            <asp:Label ID="Label1" CssClass="lbl" AssociatedControlID="txtUploadFile" runat="server" Text='<%$ Resources:labels, uploadFile %>' />
193                            <asp:FileUpload runat="server" ID="txtUploadFile" Width="400" size="50" />
194                            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="txtUploadFile" ErrorMessage="<%$ Resources:labels, required %>"
195                                ValidationGroup="fileUpload" />
196                        </li>
197                        <li style="margin:0;">
198                            <asp:Button runat="server" ID="btnUploadFile" Text="<%$Resources:labels,upload %>"
199                                ValidationGroup="fileUpload" CssClass="btn primary" OnClientClick="colorboxDialogSubmitClicked('fileUpload', 'uploadFilePanel');" /> <%=Resources.labels.or %> <a href="#" onclick="return closeOverlay();"><%=Resources.labels.cancel %></a>
200                        </li>
201                    </ul>
202                </div>
203            </div>
204
205            <table class="tblForm largeForm" style="width:100%; margin:0;">
206                <tr>
207                    <td style="vertical-align:top; padding:0 40px 0 0;">
208                        <ul class="fl">
209                            <li>
210                                <asp:Label CssClass="lbl" AssociatedControlID="txtTitle" runat="server" Text='<%$ Code: Resources.labels.title %>' />
211                                <asp:TextBox runat="server" ID="txtTitle" Width="600px" />
212                                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtTitle" 
213                                    ErrorMessage="<%$Resources:labels,enterTitle %>" Display="Dynamic" />
214                            </li>
215                            <li>
216                                <div class="editToolbar">
217                                    <asp:CheckBox runat="server" ID="cbUseRaw" Text="<%$Resources:labels,useRawHtmlEditor %>" AutoPostBack="true" />
218                                    <a href="#" id="uploadImage" class="image"><%=Resources.labels.insertImage %></a>
219                                    <a href="#" id="uploadVideo" class="video"><%=Resources.labels.insertVideo %></a>
220                                    <a href="#" id="uploadFile" class="file"><%=Resources.labels.attachFile %></a>
221                                     <a href="javascript:;" id="fileManager" class="file">File Manager</a>
222                                </div>
223                                <Blog:TextEditor runat="server" id="txtContent" />
224                                <asp:TextBox runat="server" ID="txtRawContent" Width="98%" TextMode="multiLine" Height="400px" Visible="false" />
225                            </li>
226                            <li>
227                                <asp:Label ID="Label2" CssClass="lbl" AssociatedControlID="txtSlug" runat="server" Text='<%$Resources:labels,slug %>' />
228                                <asp:TextBox runat="server" ID="txtSlug" Width="600" />
229                                <a href="javascript:void(GetSlug());"><%=Resources.labels.extractFromTitle %></a>
230                            </li>
231                            <li>
232                                <asp:Label ID="Label3" CssClass="lbl" AssociatedControlID="txtDescription" runat="server" Text='<%$Resources:labels, excerpt %>' />
233                                <asp:TextBox runat="server" ID="txtDescription" TextMode="multiLine" Columns="50" Rows="3" Width="600" Height="80" />
234                            </li>
235                            <li>
236                                <label class="lbl"><%=Resources.labels.options %></label>
237                                <asp:CheckBox runat="server" ID="cbEnableComments" Text="<%$ Resources:labels, enableComments %>" Checked="true" />
238                            </li>
239                            <li>
240                                 <asp:CheckBox runat="server" ID="cbPublish" Text="<%$ Resources:labels, publish %>" Checked="true" />
241                           </li>
242                        </ul>
243                        <div class="action_buttons">
244                            <input type="button" id="btnSave" value="<%=Resources.labels.savePost %>" class="btn primary rounded" onclick="return SavePost()" /> <%=Resources.labels.or %>
245                            <% if (!string.IsNullOrEmpty(Request.QueryString["id"]))
246                               { %>
247                            <a href="<%=PostUrl %>" title="<%=Resources.labels.goToPost %>"><%=Resources.labels.goToPost %></a>
248                            <%}
249                               else
250                               {%>
251                            <a href="Posts.aspx" title="<%=Resources.labels.cancel %>"><%=Resources.labels.cancel %></a>
252                            <%} %>
253                            <span id="autoSaveLabel" style="display:none;"></span>
254                        </div>
255                    </td>
256                    <td class="secondaryForm" style="padding:0; vertical-align:top;">
257                        <ul class="fl">
258                            <li>
259                                <asp:Label CssClass="lbl" AssociatedControlID="ddlAuthor" runat="server" Text='<%$ Code: Resources.labels.author %>' />
260                                <asp:DropDownList runat="Server" ID="ddlAuthor" />
261                            </li>
262                            <li>
263                                <asp:Label CssClass="lbl" AssociatedControlID="txtDate" runat="server" Text='<%$ Resources:labels, setPublishDate %>' />
264                                <input type="radio" name="PublishDate" id="rbtAuto" onclick="toggleAutomaticDate()" checked="checked" /><label for="rbtAuto"><%=Resources.labels.automatically %></label>
265                                <input type="radio" name="PublishDate" id="rbtManual" onclick="toggleAutomaticDate()" /><label for="rbtManual"><%=Resources.labels.manually %></label>
266                                <div id="datePanel" style="display:none;">
267                                    <asp:TextBox runat="server" ID="txtDate" Width="170" />
268                                    <asp:TextBox runat="server" ID="txtTime" Width="50" />
269                                    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="txtDate" ValidationExpression="[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]"
270                                        ErrorMessage="<%$Resources:labels,enterValidDate %>" Display="dynamic" />
271                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="txtDate" ErrorMessage="<%$Resources:labels,enterDate %>"
272                                        Display="Dynamic" />
273                                </div>
274                            </li>
275                            <li>
276                                <label class="lbl"><%=Resources.labels.categories %></label>
277                                <div class="rounded" style="overflow-y:auto; max-height:160px;border:solid 1px #dcdcdc; padding:5px; margin:0 0 5px;">
278                                    <span id="cblCategories" runat="server" class="cblCategories"></span>
279                                </div>
280                                <div style="">
281                                    <label for="<%=txtCategory.ClientID %>" style="margin-bottom:5px; display:block;"><%=Resources.labels.quickAddNewCategory %></label>
282                                    <asp:TextBox runat="server" ID="txtCategory" ValidationGroup="category" Width="150" />
283                                    <asp:Button runat="server" ID="btnCategory" Text="<%$ Resources:labels, add %>" ValidationGroup="category" CssClass="btn" style="min-width:0px; margin:0;" />
284                                    <asp:CustomValidator runat="Server" ID="valExist" ValidationGroup="category" ControlToValidate="txtCategory"
285                                        ErrorMessage="<%$ Resources:labels, categoryAlreadyExists %>" Display="dynamic" />
286                                    <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="txtCategory" ErrorMessage="<%$ Resources:labels, required %>"
287                                        ValidationGroup="category" Display="Dynamic" />
288                                </div>
289                            </li>
290                            <li style="position:relative;">
291                                <label class="lbl"><%=Resources.labels.tags%></label>
292                                <asp:TextBox runat="server" ID="txtTags" TextMode="MultiLine" Rows="3" />
293                                <span><%=Resources.labels.separateTagsWitComma %></span> <%=Resources.labels.or %>
294                                
295                                <a href="javascript:void(ToggleTagSelector())"><%=Resources.labels.chooseFromExistingTags %></a>
296                                <div id="tagselector" class="rounded" style="display: none;">
297                                    <a class="close" onclick="ToggleTagSelector()"></a>
298                                    <span><%=Resources.labels.clickTag %></span>
299                                    <div class="clear"></div>
300                                    <div style="max-height:150px; overflow-y:auto;">
301                                        <asp:PlaceHolder runat="server" ID="phTags" />
302                                    </div>
303                                    <div class="clear"></div>
304                                </div>
305                            </li>
306                        </ul>
307                    </td>
308                </tr>
309            </table>
310            <% if (Request.QueryString["id"] == null)
311               { %>
312            <script type="text/javascript">
313                setTimeout("AutoSave()", 5000);
314            </script>
315            <% } %>
316        </div>
317    </div>
318</asp:Content>