Color rows when "group by" sharepoint 2013 - sharepoint-2013

I need some help. I'm trying to set color when group by in a sharepoint list.
I'm using the following code
SP.SOD.executeFunc("clienttemplates.js", "SPClientTemplates", function() {
SPClientTemplates.TemplateManager.RegisterTemplateOverrides({
OnPostRender: function(ctx) {
var statusColors = {
'Liberada' : '#FFF1AD',
'Cancelada' : '#FFD800',
'Créditos' : '#01DF3A'
};
var rows = ctx.ListData.Row;
for (var i=0;i<rows.length;i++)
{
var status = rows[i]["Status"];
var rowId = GenerateIIDForListItem(ctx, rows[i]);
var row = document.getElementById(rowId);
row.style.backgroundColor = statusColors[status];
}
}
});
});
Can someone give a hint?

As I can see in my local Sharepoint 2013 environment, when I create a view with a group by, Sharepoint add a CSS class named « ms-gb » on the table cell that contains the group name.
Knowing this, a solution would be to edit the page of the view.
Then you can add to the page a Script Editor Webpart.
Inside this Script Editor Webpart you can add some JavaScript code to add the background-color.
Something like this for example :
<script>
$(document).ready(function(){
var statusNames = ['Liberada', 'Cancelada', 'Créditos'];
var statusColors = {
'Liberada' : '#FFF1AD',
'Cancelada' : '#FFD800',
'Créditos' : '#01DF3A'
};
$('td.ms-gb').each(function(){
for (var x=0;x<statusNames.length;x++) {
if ($(this).text().indexOf(statusNames[x]) > -1) {
$(this).css('background-color',statusColors[statusNames[x]]);
}
}
});
});
</script>
If you try this script and you don't already have a reference to JQuery in your masterpage or page layout, you will need to add one inside the script editor webpart.
You can download a local copy of JQuery or use one hosted like :
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
Hope this help.

Related

How to use custom UI for swashbuckle

I am trying to use a custom swashbuckle index.html for our .net core project. I followed the doc and done this:
app.UseSwaggerUI(c =>
{
c.IndexStream = () => GetType().Assembly
.GetManifestResourceStream("CustomUIIndex.Swagger.index.html"); // requires file to be added as an embedded resource
});
The custom index page (based on the default index.html) is loaded, but I can see the html page outputted these:
%(HeadContent)
.....
window.onload = function () {
var configObject = JSON.parse('%(ConfigObject)');
var oauthConfigObject = JSON.parse('%(OAuthConfigObject)');
So looks like the contents %(ConfigObject) or %(HeadContent) are not replaced. What should I do to get the custom index page work properly?
thanks
i mark all codes in window.onload and
the image of html source code :
https://i.stack.imgur.com/haHWm.png

change forms.py widget dynamically with user input from dropdown field in Django

I am trying to make a coding webapp in which users can write choose language and write the code.For it I am using ace editor.Ace editor requires the "mode" variable to know the language and provide syntax highlighting.
So,I have made a dropdown and I want to set the value of "mode" as the value of the dropdown field.e.g. If the users choose C++ I want mode="c++".I have the following code but I can't think of how to do it.
forms.py
from django_ace import AceWidget
class notepadModelForm(forms.ModelForm):
Your_code = forms.CharField(widget=AceWidget(mode='python', theme='clouds'))
class Meta:
model=notepadForm
fields=['Title','Your_code','Separator']
models.py
class notepadForm(models.Model):
CHOICES=[('python','Python'),('Cplusplus','C++'),('c','C')]
Title=models.CharField(max_length=120,null=False,blank=False)
Separator=models.CharField(choices=CHOICES,max_length=10,default=";")
Your_code=models.TextField(null=True,blank=True)
I have searched for it and found some examples to dynamically add fields but modifying the widget I didn't found thats why I asked it here.
You can create dropdown using javascript and the modelist extension from ace
<script src=http://ajaxorg.github.io/ace-builds/src/ace.js></script>
<script src=http://ajaxorg.github.io/ace-builds/src/ext-modelist.js></script>
<script>
var modelist = ace.require("ace/ext/modelist")
var dom = ace.require("ace/lib/dom")
// using buildDom from ace, but any other method of constructing dom can be used here
var modePicker = dom.buildDom(["select", {
value: "ace/mode/text",
onchange: function() {
editor.setOption("mode", this.value);
}
}, modelist.modes.map(function(x) {
return ["option", {
value: x.mode
}, x.caption];
})
], document.body);
var editor = ace.edit(null, {
maxLines: 10,
minLines: 5
})
document.body.appendChild(editor.container)
</script>

Laravel 5.8 parsing HTML text from database to modal

I'm trying to show HTML text which is an event program stored in database from TinyMCE textarea in a bootstrap modal.
I need to parse it before, for that I found that Laravel 5.* uses:{!! !!} to parse but with $event->program it always shows the last one stored.
here is my js code
$('#eventDetails').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var id = button.data('id')
var name = button.data('name')
var description = button.data('description')
var program = button.data('program')
var date = button.data('date')
var modal = $(this)
modal.find('.modal-body #id').text(id);
modal.find('.modal-body #name').text(name);
modal.find('.modal-body #description').text(description);
modal.find('.modal-body #program').text(program);
modal.find('.modal-body #date').text(date);
});
so what shoud I do please !!?

powerbi global object not found in typescript

I am trying to use this power bi below code where powerbi object not found error is getting in my typescript code:
// Read embed application token from textbox
var txtAccessToken = $('#txtAccessToken').val();
// Read embed URL from textbox
var txtEmbedUrl = $('#txtReportEmbed').val();
// Read report Id from textbox
var txtEmbedReportId = $('#txtEmbedReportId').val();
// Read embed type from radio
var tokenType = $('input:radio[name=tokenType]:checked').val();
// Get models. models contains enums that can be used.
var models = window['powerbi-client'].models;
// We give All permissions to demonstrate switching between View and Edit mode and saving report.
var permissions = models.Permissions.All;
// Embed configuration used to describe the what and how to embed.
// This object is used when calling powerbi.embed.
// This also includes settings and options such as filters.
// You can find more information at https://github.com/Microsoft/PowerBI-JavaScript/wiki/Embed-Configuration-Details.
var config= {
type: 'report',
tokenType: tokenType == '0' ? models.TokenType.Aad : models.TokenType.Embed,
accessToken: txtAccessToken,
embedUrl: txtEmbedUrl,
id: txtEmbedReportId,
permissions: permissions,
settings: {
filterPaneEnabled: true,
navContentPaneEnabled: true
}
};
// Get a reference to the embedded report HTML element
var embedContainer = $('#embedContainer')[0];
// Embed the report and display it within the div container.
var report = powerbi.embed(embedContainer, config);
// Report.off removes a given event handler if it exists.
report.off("loaded");
// Report.on will add an event handler which prints to Log window.
report.on("loaded", function() {
Log.logText("Loaded");
});
report.on("error", function(event) {
Log.log(event.detail);
report.off("error");
});
report.off("saved");
report.on("saved", function(event) {
Log.log(event.detail);
if(event.detail.saveAs) {
Log.logText('In order to interact with the new report, create a new token and load the new report');
}
});
in the above code the powerbi object shows not found in my typescript code: powerbi.embed(embedContainer, config);
I tried to use window['powerbi'] or window.powerbi but doesn't work. What should be the solution then?
I faced a similar issue a few weeks back (probably exactly the same). For me it seems that what works is using window.powerbi.embed() for the embed action, whereas the import import * as powerbi from "powerbi-client"; is used for all other Power BI objects.
I had the same problem, found this question through a google search. I wasn't able to figure out why it wasn't on the window, but as a work around you can initialize it yourself like this:
import * as pbi from "powerbi-client";
const powerbi = new pbi.service.Service(
pbi.factories.hpmFactory,
pbi.factories.wpmpFactory,
pbi.factories.routerFactory
);
const container = document.getElementById("report-container");
powerbi.embed(container, embedConfiguration);

Convert plain text email to clickable link - REGEX/jQuery

I am trying to convert plain text email addresses into clickable mailto links inside of a table.
I have the following function that is converting found links into mailto links, but it only seems to work for the first found link. Any subsequent links (2nd, 3rd occurrence etc.) remain as plain text links. I can't seem to figure out what I might be doing wrong. Any help would be much appreciated!
The code:
HTML
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<div class='filter-email-box'>
<div>This is a sample text which contains john#gmail.com </div>
<div>This text contains two emails adam#example.com and paul#example.com </div>
</div>
Javascript
$(".filter-email-box div").filter(function(){
var html = $(this).html();
var emailPattern = /[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/;
var matched_str = $(this).html().match(emailPattern);
if(matched_str){
$(this).html(html.replace(emailPattern,"<a href='mailto:"+matched_str+"'>"+matched_str+"</a>"));
return $(this)
}
})
Heres the fiddle I've setup:
http://jsfiddle.net/z6LF5/
When there's more than one email address, JQuery method match returns an array (when the global search flag g is set), so we're looping over that array (called matched_str in this case) and replacing the matching emails.
$(".filter-email-box div").filter(function () {
var html = $(this).html();
var emailPattern = /[a-zA-Z0-9._-]+#[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/g;
var matched_str = $(this).html().match(emailPattern);
if ( matched_str ) {
var text = $(this).html();
$.each(matched_str, function (index, value) {
text = text.replace(value,"<a href='mailto:"+value+"'>"+value+"</a>");
});
$(this).html(text);
return $(this)
}
})
JSFiddle
Use the g (global) modifier which ( finds all matches rather than stopping after the first match ).
You could implement the following:
$('.filter-email-box div').ready(function() {
$('.filter-email-box div').each(function() {
var html = $(this).html();
var regex = /([a-z0-9._-]+#[a-z0-9.-]+\.[a-z]{2,4})/ig
var text = html.replace(regex, "<a href='mailto:$1'>$1</a>");
$(this).html(text);
});
});
Fiddle
if anyone is interested I translated the jquery code to vanilla JS code
var elem = document.querySelector('.filter-email-box');
var html = elem.innerHTML;
if (html) {
var regex = /([a-z0-9._-]+#[a-z0-9.-]+\.[a-z]{2,4})/ig;
elem.innerHTML = html.replace(regex, '$1');
}
Demo link: https://jsfiddle.net/q0x4tjr3/