Dynatree - 2 links per node? - dynatree

Does anyone know if it's possible to make the DynaTree jquery plugin handle two HREF links per node?
I have one link working fine but I'm also looking at a request to display a "contacts" image on the right-hand side of each clickable node which, when clicked produces a popup (I know, not my design) of other users working on the same item.
I can display the image fairly easily using a SPAN tag but since the existing HREF is the one trapped by OnActivate, I'm having real trouble making it do anything.
All advice welcomed.

I discovered a better way.
<script type="text/javascript">
$(function () {
$("#tree").dynatree({
initAjax: {
type: "POST",
url: "TreeView/GetNodes"
// This gets data from an MVC3 controller
// in the form of a serialised list of nodes
// with custom attributes.
},
//here's the meat of it -
// elements are created and added
// according to the custom data values in the node
onRender: function (node, nodeSpan) {
if (node.data.hasPostImage) {
var postImg = document.createElement('img');
postImg.setAttribute('src', node.data.postImageUrl);
postImg.setAttribute('class', node.data.postImageClass);
postImg.setAttribute('alt', node.data.postImageAltText);
postImg.setAttribute('onClick', 'javascript:loadContacts(\'' + node.data.postImageScriptHref + '\');');
// the element is then appended to the Anchor tag (title)
// using jquery.after.
// it works really well, except for IE7. Working on that now.
$(nodeSpan).find('.dynatree-title').after(postImg);
}
},
onClick: function (node) {
node.toggleExpand();
}
});
});
</script>

I noticed that outputting the tree directly allowed me to embed an image tag in the structure as follows -
<div id="tree">
<ul id="treeData" style="display: none;">
#foreach (var provider in Model.Locations)
{
<li class="folder" data="icon: 'false', addClass: 'root-node'">#provider.Provider
<ul>
#foreach (var profession in provider.ChildLocations)
{
<li id="#profession.Id">#profession.Profession <img class="contactsImg" onclick="loadContacts();" src="../../Content/themes/default/images/icons/contacts.png" />
<ul>
#foreach (var formtype in profession.ChildLocations)
{
<li class="folder" id="#formtype.Id" data="addClass: 'progress-bar'">#formtype.Type
<ul>
#foreach (var form in formtype.ChildLocations)
{
<li id="#form.Id" data="addClass: 'progress-bar'">#Ajax.ActionLink(form.Form, "PartialIndex", "FormCover", new { Id = form.formId }, new AjaxOptions { UpdateTargetId = "contentpanel" })
<ul>
#foreach (var lo in form.ChildLocations)
{
<li id="#lo.Id" data="addClass: 'action-required'">#Ajax.ActionLink(lo.Name, "ActualFormTab", new {formid = form.formId, layoutid = lo.formId}, new AjaxOptions{ UpdateTargetId = "contentpanel"})</li>
}
</ul>
</li>
}
</ul>
</li>
}
</ul>
</li>
}
</ul>
</li>
}
</ul>
</div>
And that, as demonstrated, it was pretty straightforward to add an OnClick event to the image.

Related

vue component compilation issue

I'm pretty new to Vue.js so bear with me. I'm working on a project where I created two new vue components, one is a tab/toggle element, the other is a cookie banner. However, when both are added to the page the cookie banner does not compile. The HTML is rendered but it still contains all the vue syntax in its uncompiled form. Does anyone see where the conflict is occurring between these two components? I don't see any errors in the console so I'm at a loss on how to begin debugging.
Component 1:
(function () {
var _instance = new Vue({
el: "#multiTrackSwiper",
data: {
tabs: {}
},
methods: {
checkActiveTab: function (index) {
if (this.tabs['active']) {
return this.tabs['active'] === index;
} else {
return index === "0";
}
},
handlerActiveTab: function (index) {
Vue.set(this.tabs, 'active', index);
}
}
});
})();
#using Sitecore.Feature.Media.Models.Components
#model List<ITrackWithCarousel>
#if (Model != null && Model.Count > 0)
{
if (Model.Count == 1)
{
<div class="c-product-details__track">
#Html.Partial("TrackWithCarousel", Model[0])
</div>
}
else
{
var index = 0;
<div id="multiTrackSwiper" class="multi-track-swiper" vue-instance v-cloak>
<ul class="nav nav-tabs">
#foreach (var track in Model)
{
<li class="nav-item">
<button id="tab_#track.Name.Replace(" ","_")" data-bs-toggle="tab" class="nav-link"
v-bind:class="{ 'active':checkActiveTab('#index') }"
v-on:click="handlerActiveTab('#index')">
#track.DisplayName
</button>
</li>
index++;
}
</ul>
#{ index = 0; }
#foreach (var track in Model)
{
<div class="c-product-details__track c-product-details__multitrack" aria-labelledby="tab_#track.Name.Replace(" ","_")"
v-bind:class="{ 'active':checkActiveTab('#index') }">
#Html.Partial("TrackWithCarousel", track)
</div>
index++;
}
</div>
}
}
Component 2:
(function () {
var _instance = new Vue({
el: "#cookie-banner",
data: {
cookieSaved: null
},
methods: {
saveSessionCookie: function () {
var expiry = (new Date(Date.now() + 600 * 1000)).toUTCString(); // 3 days 259200
document.cookie = "cookie-banner-closed=true; expires=" + expiry + ";path=/;"
this.cookieSaved = true;
}
},
mounted: function () {
if (document.cookie.includes('cookie-banner-closed')) {
this.cookieSaved = true;
} else {
this.cookieSaved = null;
}
}
});
})();
<div id="cookie-banner" vue-instance v-cloak>
<div class="cookie-disclaimer" v-if="!cookieSaved">
<div id="cookie-notice">
<div class="cookie-inner-module h-spacing">
This website uses cookies. We do this to better understand how visitors use our site and to offer you a more personal experience. We share information about your use of our site with social media and analytics partners in accordance with our Privacy Notice</a>.
<i class="fas fa-times" v-on:click="saveSessionCookie"></i>
</div>
</div>
</div>
</div>
I've tried switching both vue components into vue instances instead but that doesn't resolve the issue.
The HTML is rendered but it still contains all the vue syntax in its uncompiled form.
I don't think that you are using Vue format/syntax. So it will render what you are typed inside html.

Using PartialView to create dynamic MainMenu in _Layout Page - Asp.net core razorpage

i want to using PartialView in My _Layout Page
and this is my PartialView code:
#model List<WebApplication4.Models.MainMenuTable>
#foreach (var item in Model)
{
<li class="nav-item">
<a class="nav-link text-dark" asp-page="#item.Link">#item.Title</a>
</li>
}
and this is my _Layout Page code:
#{
var partialModel = new List<MainMenuTable>()
{
};
}
and:
<partial name="_MainMenu" model="partialModel"/>
but i saw nothing in result why?
Your code is OK, But you need to pass some data into Partial View when you use it in _Layout.cshtml, Refer to this simple demo:
#{
var partialModel = new List<MainMenuTable>()
{
new MainMenuTable
{
Title = "HomePage",
Link = "index"
},
new MainMenuTable
{
Title = "PrivacyPage",
Link = "Privacy"
}
};
}
<partial name="_MainMenu" model="partialModel"/>
When you don't pass any data into Partival View, It will not show in your _Layout.

meteor dynamic meta tags

Well, i need some way to have a dynamic meta tags for my app, im creating a cms-blog so ill need to change the meta desc/keywords/title etc at every post,im using iron-router.
i have an idea how to do so using not completely sure:
<template name="post">
{{metaTitle}}
</template>
Template.post.metaTitle = function (this) {
document.title = this;
}
(iron-router version)
this.route('post', {
path: '/',
....
data: function () {
return Posts.findOne({_id: this.params._id});
}
//Posts holds post documents with a fields like: "metaTitle" "metaKeywords" etc
});
so if a client routes to "/" and the Posts collection holds a post with id of "/"
and the document holds metaTitle:"Post 1"
will this proceed to the template.post.metaTitle helper
and the title will be "Post 1"?
is there a better way?
and doing similar stuff to the keywords etc.
ok , i have manged to do this, here is what i'v done:
html:
<template name="posts">
{{metaTitle}}
{{metaDesc}}
{{metaKeywords}}
{{>home}}
{{#each posts}}
</div>
<a href="{{pathFor 'post'}}">
<div class="small-12 medium-12 large-12 columns">
<div class="post">
<div class="small-12 medium-12 large-12 columns">
<h4 class="left">{{author}}</h4>
<h4 class="right">{{date}}</h4>
</div>
<h2>{{title}}</h2>
<p>{{desc}}</p>
</div>
</div>
</a>
<hr/>
{{/each}}
</template>
router (iron-router):
this.route('posts', {
path: '/',
waitOn:function(){
NProgress.start();
Meteor.subscribe("Teams");
},
before: function () {
Session.set("adding_group", false);
NProgress.done();
/*
causes problems when phonegap mode
*/
},
fastRender:true,
unload: function () {
Session.set("adding_group", true);
Session.set("group_name", false);
Session.set("group_date", false);
Session.set("group_friends", false);
Session.set("group_location", false);
Session.set("group_rules", false);
Session.set("group_desc", false);
Session.set("group_save", false);
},
yieldTemplates: {
'nav': {to: 'header'}
},
data:{
posts:Posts.find({}),
metaTitle:function(){
var one = Posts.findOne({}); //just for the example
return document.title = one.title; //just for the example
}
}
});
this will insert a document.title of the posts if ill do this dynamic path segments
( findOne by ID ) it will return the current post title,
i think ill make this simple thing a package, i haven't seen similar package at atmosphere.
hope it helps you guys.

MVC4 Web Grid Sorting and Pagination Issue

I am using Web Grid in MVC4 web application. I have a search functionality in the page. Web grid works fine i.e Sorting and Paging works fine until there is no search performed. When a search is performed, then sorting the web grid does not sort those searched results alone but sorts the entire list of items.
I debugged and found that during click of Web grid header for sorting, it redirects to HttpGet method and not HttpPost.I am pretty sure that if HTTPPOST is hit, then this problem would vanish.
I tried searching in google but could not find any specific answers. Any help or pointers would be greatly appreciated. Hope I am clear on my problem.
Controller:
public ActionResult Index()
{
var item = GetAllActors();
return View(item);
}
[HttpPost]
public ActionResult Index(string SearchContion, FormCollection collection)
{
var item = GetAllActors();
List<ActorBE> listOfItems = new List<ActorBE>();
if (item != null && collection != null)
{
if (!string.IsNullOrEmpty(SearchContion))
{
List<string> searchResults = item.FindAll(s => s.ActorName.IndexOf(SearchContion, StringComparison.OrdinalIgnoreCase) >= 0).Select(p => p. ActorName).ToList();
foreach (var data in searchResults)
{
ActorBE actor = new ActorBE ();
actor = item.Where(l => l.ActorName == data).FirstOrDefault();
listOfItems.Add(actor);
}
return View(listOfItems);
}
else
{
return View(item);
}
}
else
{
return View();
}
}
View:
#model IEnumerable<Tool.DataService.ActorBE>
#{
ViewBag.Title = "Actor";
Layout = "~/Views/Shared/_Layout.cshtml";
WebGrid grid = new WebGrid(rowsPerPage: 50, canPage: true, canSort: true);
grid.Pager(WebGridPagerModes.All);
grid.Bind(Model, rowCount: Model.ToList().Count());
}
#using (Html.BeginForm())
{
#Html.ValidationSummary(true)
<div style="padding: 2px 2px 2px 2px;">
<fieldset>
<legend>Search</legend>
<header>
<div class="content-wrapper">
<div class="float-left">
<label style="display:inline;margin-right:5px">Actor Name</label>
#Html.TextBox("SearchContion")
<input type="submit" value="Search" name="Search" style="border-radius:5px;margin-left:5px;"/>
</div>
</div>
</header>
</fieldset>
</div>
#grid.GetHtml(htmlAttributes: new
{ id = "grid" },
tableStyle: "webgrid",
headerStyle: "webgrid-header",
footerStyle: "webgrid-footer",
alternatingRowStyle: "webgrid-alternating-row",
selectedRowStyle: "webgrid-selected-row",
firstText:"First",
lastText:"Last",
nextText:"Next",
mode: WebGridPagerModes.All,
previousText:"Previous",
rowStyle: "webgrid-row-style", columns: grid.Columns
(
grid.Column("ActorID",header:"Actor ID, style:"column", canSort:true),
grid.Column("ActorName",header:"Actor Name", style:"width:200px", canSort:true),
grid.Column
("",
header:"Actions",
format:#<text>
#Html.ActionLink("Edit", "Edit", new { id = item.ActorID })
#if (item.IsActive)
{
#Html.ActionLink("Deactivate", "Delete", new { id = item. ActorID })
}
</text>
)
)
)
}
When user searches some actor name, the search results are happening properly. Once search is over, when the user clicks on web grid headers, then search results are not retained properly but the control again goes to HttpGET Method and not to the HTTPPOST Method. This s the main problem.
Guide me on how to solve this problem
As a work around what you can do is when search is performed save the state of the Grid on server so that you can check for it while rendering the grid again, a similar question was answered here https://stackoverflow.com/a/15528219/335105

displaying models on different div ember.js

In Ember.js, what is the best way to display a models properties?
Say my model is 'products' so I have a product list, when I click on an item on that list I want the details displayed in another div and not override that view.
How can I do this, below if my code.
<script type="text/x-handlebars">
{{ view App.ListReleasesView }}
</script>
<script type="text/x-handlebars">
{{ view App.ReleaseDataView }}
</script>
App.ListReleasesView = Ember.View.extend({
templateName: 'app/templates/releases/list',
releasesBinding: 'App.releasesController',
showNew: function() {
this.set('isNewVisible', true);
},
hideNew: function() {
this.set('isNewVisible', false);
},
refreshListing: function() {
App.releasesController.findAll();
}
});
App.selectedReleaseController = Ember.Object.create({
release: null
});
list template:
<ul>
{{#each releases}}
{{view App.ShowReleaseView releaseBinding="this"}}
{{/each}}
</ul>
{{#if isNewVisible}}
{{view App.NewReleaseView}}
{{/if}}
<div class="commands">
<a href="#" {{action "showNew"}}>New Release</a>
<a href="#" {{action "refreshListing"}}>Refresh Listing</a>
</div>
App.ShowReleaseView = Ember.View.extend({
templateName: 'app/templates/releases/show',
//classNames: ['show-release'],
classNameBindings: ['isSelected'],
// tagName: 'tr',
doubleClick: function() {
// this.showEdit();
// this.showRelease();
var release = this.get("release");
App.selectedReleaseController.set("release", release);
},
isSelected: function(){
var selectedItem = App.selectedReleaseController.get("release");
release = this.get("content");
if (release === selectedItem) {return true; }
}.property('App.selectedReleaseController.release')
show template:
{{#if App.selectedReleaseController.release}}
{{view App.ReleaseDataView}}
{{else}}
{{release.name}}
{{/if}}
App.ReleaseDataView = Ember.View.extend({
templateName: 'app/templates/releases/releaseData',
releaseBinding: 'App.selectedReleaseController.release',
// classNames: ['release'],
});
release template:
{{#if isSelected}}
<div class="name">
{{editable "release.name"}} {{editable "release.description"}}
</div>
{{/if}}
You'll want to have a simple controller whose job will be managing the selection state.
App.selectedReleaseController = Ember.Object.create({
content: null
});
Then you'll have another view, for the details, which is bound to that controller.
{{view App.ReleaseDetailsView releaseBinding="App.selectedReleaseController.content"}}