Permalink
Browse files

started adding shadow templates feature

  • Loading branch information...
markentingh committed May 27, 2017
1 parent ec07442 commit 6362e2de165ac5f328d3be3449aa16dcfa7ca40d
@@ -31,6 +31,19 @@ public override Services.Inject LoadSubPage(string path)
scaffold.Data["page-list"] = servePage.View(websiteId, 0, 1, 1000, 4, 0, "");
S.javascriptFiles.Add("dash-pages", "/js/dashboard/pages/pages.js");
S.javascript.Add("dash-pages", "S.dashboard.pages.init();");
//get list of available shadow templates
var reader = page.sql.GetShadowTemplatesForWebsite(page.websiteId);
var js = "S.dashboard.pages.shadow_templates = [";
var i = 0;
while (reader.Read())
{
if(i > 0) { js += ","; }
js += "{id:" + reader.GetInt("pageId").ToString() + ", title:'" + reader.Get("title").Replace("'", "\\'") + "'}";
i++;
}
js += "];";
S.javascript.Add("dash-page-shadows", js);
}
inject.html = scaffold.Render();
@@ -215,13 +228,13 @@ private string RenderListItem(Scaffold item, string color, int pageId, string pa
#region "Create"
public string Create(int websiteId, int parentId, string title, string description, int type, bool secure, string layout = "", string service = "")
public string Create(int websiteId, int parentId, string title, string description, int type, int shadowId, int shadowChildId, bool secure, string layout = "", string service = "")
{
if (!S.User.checkSecurity(websiteId, "dashboard/pages", User.enumSecurity.create)) { return "err"; }
//create new web page
GetPage();
page.sql.Create(S.User.userId, websiteId, parentId, title, description, (SqlQueries.Page.enumPageType)Enum.Parse(typeof(SqlQueries.Page.enumPageType), type.ToString()), layout, service, secure);
page.sql.Create(S.User.userId, websiteId, parentId, title, description, (SqlQueries.Page.enumPageType)Enum.Parse(typeof(SqlQueries.Page.enumPageType), type.ToString()), shadowId, shadowChildId, layout, service, secure);
//return list of sub-pages
return View(websiteId, parentId, 0, 100, 0, 0, "");
@@ -244,6 +257,10 @@ public string ViewSettings(int id)
scaffold.Data["description"] = reader.Get("description");
scaffold.Data["secure"] = reader.GetBool("security") ? "checked=\"checked\"" : "";
scaffold.Data["active"] = reader.GetBool("enabled") ? "checked=\"checked\"" : "";
scaffold.Data["use-shadow"] = reader.GetInt("shadowId") > 0 ? "checked=\"checked\"" : "";
scaffold.Data["use-child-shadow"] = reader.GetInt("shadowChildId") > 0 ? "checked=\"checked\"" : "";
scaffold.Data["shadow-id"] = reader.GetInt("shadowId").ToString();
scaffold.Data["shadow-child-id"] = reader.GetInt("shadowChildId").ToString();
switch (reader.GetShort("pagetype"))
{
case 0: scaffold.Data["pagetype"] = "1"; break;
@@ -254,16 +271,20 @@ public string ViewSettings(int id)
return scaffold.Render();
}
public string UpdateSettings(int websiteId, int id, string title, string description, int type, bool secure, bool active)
public string UpdateSettings(int websiteId, int id, string title, string description, int type, int shadowId, int shadowChildId, bool secure, bool active)
{
if (!S.User.checkSecurity(websiteId, "dashboard/pages", User.enumSecurity.update)) { return "err"; }
//create new web page
GetPage();
page.sql.Update(websiteId, id, title, description, (SqlQueries.Page.enumPageType)Enum.Parse(typeof(SqlQueries.Page.enumPageType), type.ToString()), "", "", secure, active);
page.sql.Update(websiteId, id, title, description, (SqlQueries.Page.enumPageType)Enum.Parse(typeof(SqlQueries.Page.enumPageType), type.ToString()), shadowId, shadowChildId, "", "", secure, active);
return "success";
}
#endregion
#region "Shadow Templates"
#endregion
}
}
@@ -121,25 +121,60 @@ <h4>Create #create-title#</h4>
<div class="col field-label">Summary</div>
<div class="col field-input expand"><textarea id="txtcreatedesc" placeholder="Write a description about your new page"></textarea></div>
</div>
<div class="row hover">
<div class="col field-label">Page Type</div>
<div class="col field-input">
<select id="pagetype">
<option value="0" selected="selected">Web Page</option>
<option value="2">Shadow Page</option>
</select>
</div>
</div>
<div class="row text-right pad-top desc-chars font-faded"></div>
<div class="row pad-top pad-bottom-sm title"><h6>Security</h6></div>
<div class="row hover margin-bottom-lg">
<div class="row hover margin-bottom-sm">
<div class="col field-label"></div>
<div class="col field-text">
<label>
<input type="checkbox" class="chk-secure" /><span>Private</span>
<span class="font-faded pad-left">Only administrators can view this web page</span>
</label>
</div>
</div>
<div class="row pad-top pad-bottom-sm">
<div class="col title"><h6>Shadow Template</h6></div>
<div class="col right"><a href="javascript:" class="button special">New Shadow Template</a></div>
</div>
<div class="row hover">
<div class="col field-label"></div>
<div class="col field-text pad-right" style="width:400px;">
<label>
<input type="checkbox" class="chk-use-shadow" /><span>Use a Shadow Template for this web page</span>
</label>
</div>
<div class="shadow-list" style="display:none;">
<div class="col field-text icon tiny pad-right">
<svg viewBox="0 0 32 32">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-arrow-right" x="0" y="0" width="32" height="32"></use>
</svg>
</div>
<div class="col field-input pad-right">
<select id="shadowId">
{{shadow-list}}
</select>
</div>
</div>
</div>
<div class="row hover margin-bottom-lg">
<div class="col field-label"></div>
<div class="col field-text pad-right" style="width:400px;">
<label>
<input type="checkbox" class="chk-use-child-shadow" /><span>Assign a Shadow Template to new child pages</span>
</label>
</div>
<div class="shadow-child-list" style="display:none;">
<div class="col field-text icon tiny pad-right">
<svg viewBox="0 0 32 32">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-arrow-right" x="0" y="0" width="32" height="32"></use>
</svg>
</div>
<div class="col field-input">
<select id="shadowChildId">
{{shadow-list}}
</select>
</div>
</div>
</div>
</div>
@@ -1,5 +1,5 @@
S.dashboard.pages = {
current_page: 0, current_path: [], page_info: null, slides: null,
current_page: 0, current_path: [], page_info: null, slides: null, shadow_templates: [],
init: function(){
this.slides = new S.slides('.pages-info > .slideshow');
@@ -104,7 +104,8 @@
var data = {
'parent-title': info.path != '' ? 'For page "' + info.path.replace(/\//g, ' > ') + '"' : '',
'page-url': info['url-name'] + '/',
'create-title': pageid == 0 ? 'Page' : 'Sub Page'
'create-title': pageid == 0 ? 'Page' : 'Sub Page',
'shadow-list': ''
}
var scaffold = new S.scaffold(htm, data);
var container = $(e).parents('.page-details').find('.page-create');
@@ -122,6 +123,30 @@
container.find('.btn-page-cancel a').on('click', S.dashboard.pages.create.cancel);
$('#txtcreatedesc').on('keyup', S.dashboard.pages.create.countChars);
$('#txtcreatetitle').on('keyup', S.dashboard.pages.create.updateTitle);
container.find('.chk-use-shadow').on('change', function (e) {
if (e.target.checked) {
$('.shadow-list').show();
} else {
$('.shadow-list').hide();
}
});
container.find('.chk-use-child-shadow').on('change', function (e) {
if (e.target.checked) {
$('.shadow-child-list').show();
} else {
$('.shadow-child-list').hide();
}
});
//load shadow template list into drop down lists
var list = '';
var templates = S.dashboard.pages.shadow_templates;
for (var x = 0; x < templates.length; x++) {
list += '<option value="' + templates[x].id + '">' + templates[x].title + '</option>';
}
$('#shadowId, #shadowChildId').html(list);
if (pageid > 0) {
var subpages = $(e).parents('.page-details').find('.slideshow');
subpages.addClass('hide');
@@ -201,15 +226,22 @@
return false;
}
//submit "create page" form
S.ajax.post("Dashboard/Pages/Create", {
data = {
websiteId: S.dashboard.website.id,
parentId: S.dashboard.pages.current_page,
type:0,
title: title,
description: desc,
type: container.find('#pagetype').val(),
shadowId: container.find('#shadowId').val(),
shadowChildId: container.find('#shadowChildId').val(),
secure: secure
},
};
if (data.shadowId == '' || !container.find('.chk-use-shadow')[0].checked) { data.shadowId = 0; }
if (data.shadowChildId == '' || !container.find('.chk-use-child-shadow')[0].checked) { data.shadowChildId = 0; }
//submit "create page" form
S.ajax.post("Dashboard/Pages/Create", data,
function (data) {
if (data.d == 'err') {
S.message.show(msg, 'error', 'An error occurred while trying to create your new web page');
@@ -261,6 +293,48 @@
container.find('.btn-page-cancel a').on('click', S.dashboard.pages.settings.cancel);
$('#description').on('keyup', S.dashboard.pages.settings.countChars);
//add events for shadow templates
container.find('.chk-use-shadow').on('change', function (e) {
if (e.target.checked) {
$('.shadow-list').show();
} else {
$('.shadow-list').hide();
}
});
container.find('.chk-use-child-shadow').on('change', function (e) {
if (e.target.checked) {
$('.shadow-child-list').show();
} else {
$('.shadow-child-list').hide();
}
});
//check shadow checkboxes
if (container.find('.chk-use-shadow')[0].checked) {
$('.shadow-list').show();
} else {
$('.shadow-list').hide();
}
if (container.find('.chk-use-child-shadow')[0].checked) {
$('.shadow-child-list').show();
} else {
$('.shadow-child-list').hide();
}
//load shadow template list into drop down lists
var list = '';
var templates = S.dashboard.pages.shadow_templates;
for (var x = 0; x < templates.length; x++) {
list += '<option value="' + templates[x].id + '">' + templates[x].title + '</option>';
}
container.find('#shadowId, #shadowChildId').html(list);
//select shadow template from list
container.find('#shadowId option').removeAttr('selected');
container.find('#shadowId option[value="' + container.find('#shadowId').attr('data-id') + '"]').attr('selected', 'selected');
container.find('#shadowChildId option').removeAttr('selected');
container.find('#shadowChildId option[value="' + container.find('#shadowChildId').attr('data-id') + '"]').attr('selected', 'selected');
//show settings section
var subpages = $(e).parents('.page-details').find('.slideshow');
subpages.addClass('hide');
@@ -326,16 +400,23 @@
return false;
}
//submit "page settings" form
S.ajax.post("Dashboard/Pages/UpdateSettings", {
var data = {
websiteId: S.dashboard.website.id,
id: S.dashboard.pages.settings.id,
title: titlehead,
description: desc,
type: container.find('#pagetype').val() || -1,
type: 0,
shadowId: $('#shadowId').val(),
shadowChildId: $('#shadowChildId').val(),
secure: secure,
active: active
},
};
if (!$('.chk-use-shadow')[0].checked) { data.shadowId = 0; }
if (!$('.chk-use-child-shadow')[0].checked) { data.shadowChildId = 0; }
//submit "page settings" form
S.ajax.post("Dashboard/Pages/UpdateSettings", data,
function (data) {
if (data.d == 'err') {
S.message.show(msg, 'error', 'An error occurred while trying to create your new web page');
@@ -18,26 +18,6 @@ <h4>Page Settings for {{page-title}}</h4>
<div class="col field-input expand"><textarea id="description">{{description}}</textarea></div>
</div>
<div class="row text-right pad-top desc-chars font-faded"></div>
{{pagetype}}
<div class="row hover">
<div class="col field-label">Page Type</div>
<div class="col field-input">
<select id="pagetype">
<option value="0" selected="selected">Web Page</option>
<option value="2">Shadow Page</option>
</select>
</div>
</div>
{{/pagetype}}
{{pagetype-shadow}}
<div class="row hover">
<div class="col field-label">Page Type</div>
<div class="col field-text label">
Shadow Page <span class="faded">(cannot be changed)</span>
</div>
</div>
{{/pagetype-shadow}}
<div class="row pad-top pad-bottom-sm title"><h6>Security</h6></div>
<div class="row hover">
@@ -58,6 +38,51 @@ <h4>Page Settings for {{page-title}}</h4>
</label>
</div>
</div>
<div class="row pad-top pad-bottom-sm">
<div class="col title"><h6>Shadow Template</h6></div>
<div class="col right"><a href="javascript:" class="button special">New Shadow Template</a></div>
</div>
<div class="row hover">
<div class="col field-label"></div>
<div class="col field-text pad-right" style="width:400px;">
<label>
<input type="checkbox" class="chk-use-shadow" {{use-shadow}}/><span>Use a Shadow Template for this web page</span>
</label>
</div>
<div class="shadow-list" style="display:none;">
<div class="col field-text icon tiny pad-right">
<svg viewBox="0 0 32 32">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-arrow-right" x="0" y="0" width="32" height="32"></use>
</svg>
</div>
<div class="col field-input pad-right">
<select id="shadowId" data-id="{{shadow-id}}">
{{shadow-list}}
</select>
</div>
</div>
</div>
<div class="row hover margin-bottom-lg">
<div class="col field-label"></div>
<div class="col field-text pad-right" style="width:400px;">
<label>
<input type="checkbox" class="chk-use-child-shadow" {{use-child-shadow}}/><span>Assign a Shadow Template to new child pages</span>
</label>
</div>
<div class="shadow-child-list" style="display:none;">
<div class="col field-text icon tiny pad-right">
<svg viewBox="0 0 32 32">
<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#icon-arrow-right" x="0" y="0" width="32" height="32"></use>
</svg>
</div>
<div class="col field-input">
<select id="shadowChildId" data-id="{{shadow-child-id}}">
{{shadow-list}}
</select>
</div>
</div>
</div>
</div>
</div>
<div class="absolute bottom row pad-bottom pad-width">
<div class="col btn-page-settings-update pad-right"><a class="button" href="javascript:">Update Page Settings</a></div>
@@ -63,10 +63,8 @@
switch (k) {
case 67: //c (copy)
return false;
break;
case 86: //v (paste)
return false;
break;
case 88: //x (cut)
break;
case 89: //y (redo)
Submodule selector deleted from b1c879
Oops, something went wrong.

0 comments on commit 6362e2d

Please sign in to comment.