Sharing #functions between Orchard custom theme's views - function

I'm porting an existing site in orchard, unfortunately the existing css is not very well stuctured and i need several helper functions to make the site work correctly.
currently i'm rewriting these conversion functions in each of the shape's alternate .cshtml file i'm customizing.
It is always the same function, and i want to move it in some location to make it reusable and more easilly maintanable.
I would also like to have it theme-specific (inside the folder of the theme i'm creating)
the function is very trivial
#functions{
string ConvertColorToStyle(string color){
string menuStyle = "";
switch(color)
{
case "Azure": menuStyle = "secondary_nav_area"; break;
case "DarkGreen": menuStyle = "secondary_nav_areaDiscoServices"; break;
case "LightGreen": menuStyle = "secondary_nav_areaPreClinAndClinical"; break;
case "Violet": menuStyle = "secondary_nav_areaAPI"; break;
case "LightViolet": menuStyle = "secondary_nav_areaSSC"; break;
case "DarkAzure": menuStyle = "secondary_nav_areaPharma"; break;
case "DeepAzure": menuStyle = "secondary_nav_areaIDFDaM"; break;
case "DeepBlue": menuStyle = "secondary_nav_areaIDDS"; break;
case "Orange": menuStyle = "secondary_nav_areaClinServices"; break;
case "Cyan": menuStyle = "secondary_nav_areaConsulting"; break;
case "Indigo": menuStyle = "secondary_nav_areaINDiGO"; break;
case "LightAzure": menuStyle = "secondary_nav_areaPAC"; break;
default: menuStyle = "secondary_nav_area";
break;
}
return menuStyle;
}}
but i want to share it across views like what it is possible to do by putting a function.cshtml file in the App_Code folder of an asp.net mvc project.
Is there a way to share this function across all the views in my theme in Orchard?

Sure: add a project file to your theme that has the same name as the theme, then add a cs file to it with a static class that exposes that method. You'll then be able to use the function in your views.

Related

Is that possible to use canvas element in DOM jQuery?

I am new to jquery.
Is that possible to add canvas class in DOM jquery?
The canvas class include Skycons's icons that I want to use for my api.
$.ajax ({
url: "url",
type: "GET",
dataType: 'json',
success: function(e) {
let icon = e.weather[0].icon;
switch (icon) {
case "01d":
icon = "CLEAR_DAY";
break;
case "01n":
icon = "CLEAR_NIGHT";
break;
case "02d":
icon = "PARTLY_CLOUDY_DAY";
break;
case "02n":
icon = "PARTLY_CLOUDY_NIGHT";
break;
case "03d":
icon = "CLOUDY";
break;
case "03n":
icon = "CLOUDY";
break;
case "04d":
icon = "CLOUDY";
break;
case "04n":
icon = "CLOUDY";
break;
case "09d":
icon = "RAIN";
break;
case "09n":
icon = "RAIN";
break;
case "10d":
icon = "RAIN";
break;
case "10n":
icon = "RAIN";
break;
case "11d":
icon = "RAIN";
break;
case "11n":
icon = "RAIN";
break;
case "13d":
icon = "SNOW";
break;
case "13n":
icon = "SNOW";
break;
case "50d":
icon = "FOG";
break;
case "50n":
icon = "FOG";
break;
}
Then adding function
setIcons(icon, document.querySelector(".icon"));
function setIcons(icon, iconID) {
const skycons = new Skycons({ color: "white" });
const currentIcon = icon;
skycons.play();
return skycons.set(iconID, Skycons[currentIcon]);
}
let variable ='';
variable += '<div class="row h-100">';
variable += ' <canvas class="icon" width="128" height="128"></canvas>';
variable += '</div>';
$('#letWeather').html(variable);
}
});
Then add this id to Html..
<div id="letWeather"></div>
It doesn't displaying...
But if I am adding this to HTML, outside of DOM. It does works. Why?
<canvas class="icon" width="128" height="128"></canvas>
Look at the order you are doing things in.
First you search the DOM for an element with the class icon and you do stuff with whatever you find.
Next you create a string with some HTML in it that includes an element with that class.
Finally you use that HTML to add that element to the DOM.
You aren't going to find it if you search the DOM for it before you add it to the DOM.

Switch cases in a google sheets script failing to recognize certain cases when typed into cell, but work when copy+pasted

This is a very simple script and I have noted the cases that are failing.
The cases I tested the most was 'ts' when I type it into the cell, the value is not replaced, but when I copy from the script and paste it into the cell it does replace the value.
I have retyped that line of code multiple times to make sure that there is not an extra space within the quotes.
Any insight into why this is happening is much appreciated.
switch (e.value) {
case 'n':
e.range.setValue('=Sheet5!B1');
break;
case 't':
e.range.setValue('=Sheet5!B2');
break;
case 'i': //fails
e.range.setValue('=Sheet5!B3');
break;
case 'c':
e.range.setValue('=Sheet5!B4');
break;
case 's': //fails
e.range.setValue('=Sheet5!B5');
break;
case 'st':
e.range.setValue('=Sheet5!B6');
break;
case 'si': //fails
e.range.setValue('=Sheet5!B7');
break;
case 'sc':
e.range.setValue('=Sheet5!B8');
break;
case 'ts': //fails
e.range.setValue('=Sheet5!B6');
break;
case 'is': //fails
e.range.setValue('=Sheet5!B7');
break;
case 'cs':
e.range.setValue('=Sheet5!B8');
break;
case 'd': //fails
e.range.setValue('=Sheet5!B9');
break;
default:
return;
}
return;
}```
This works if you create and installable onEdit trigger since your changing values you can't use a simple trigger.
function onYourEdit(e) {
var sh=e.range.getSheet();
if(sh.getName()!='Sheet10')return;
switch (e.value) {
case 'n':
e.range.setValue('=Sheet11!B1');
break;
case 't':
e.range.setValue('=Sheet11!B2');
break;
case 'i': //fails
e.range.setValue('=Sheet11!B3');
break;
case 'c':
e.range.setValue('=Sheet11!B4');
break;
case 's': //fails
e.range.setValue('=Sheet11!B5');
break;
case 'st':
e.range.setValue('=Sheet11!B6');
break;
case 'si': //fails
e.range.setValue('=Sheet11!B7');
break;
case 'sc':
e.range.setValue('=Sheet11!B8');
break;
case 'ts': //fails
e.range.setValue('=Sheet11!B6');
break;
case 'is': //fails
e.range.setValue('=Sheet11!B7');
break;
case 'cs':
e.range.setValue('=Sheet11!B8');
break;
case 'd': //fails
e.range.setValue('=Sheet11!B9');
break;
default:
return;
}
return;
}

Line 49, 52,55,58,61,64- 1119:Access of possibly undefined property text through a reference with static type String

Not sure what I am doing wrong, I removed any text from the text box fields so why am I still getting this error ?
Code below :
switch (day) {
case "Sun":
day.text = "Monday";
break;
case "Mom":
day.text = "Tuesday";
break;
case "Tue":
day.text = "Wednesday";
break;
case "Wed":
day.text = "Thursday";
break;
case "Thu":
day.text = "Friday";
break;
case "Fri":
day.text = "Saturday";
break;
case "Sat":
day.text = "Sunday";
break;
}
switch (codeToday) {
case "0":
case "3200":
var weather00:weather00 = new weather00();
_weatherToday.addChild(weather00);
_weatherToday.scaleX = 10.85;
_weatherToday.scaleY = 158.75;
break;
case "1":
case "3200":
var weather01:weather01 = new weather01();
_weatherToday.addChild(weather01);
_weatherToday.scaleX = 10.85;
_weatherToday.scaleY = 158.75;
break;
}
i suppose that 'day' is a String variable and have not a text property - look here -> String
Some components have a text property like: TextField and TextArea

i getting stack overflow error in as3

i am a beginner in flash but not in object oriented progarming.
iam making a business simulation multiplayer board game.this salute function is called from an .fla file and this salute function calls moveto function.the salute function working fine.but the problem comes at moveto() at dialog2.x=200;.if i remove that line the problem goes to next line please help me
public function salute(a:Array)
{
a[0].x=200;
a[0].y=200;
if(k==0)
{
tilehold.amount.text=String(amount);
tilehold.networth.text=String(networth);
tilehold.playertitle.text=playername;
dialog2=a[1];
dialog3=a[2];
dialog4=a[3];
dialog5=a[4];
dialog6=a[5];
forbuild=a[6];
k=1
}
a[0].dialogtext.text=playername+"'s turn";
a[0].addEventListener(MouseEvent.MOUSE_DOWN,nothing1);
function nothing1(e:MouseEvent)
{
a[0].x=1000;
e.target.removeEventListener(MouseEvent.MOUSE_DOWN,nothing1);
a[7].x=-10;
a[7].y=-10;
a[7].addEventListener(MouseEvent.CLICK,wheelspin);
}
function wheelspin(e:MouseEvent)
{
spinvalue=Math.floor(Math.random()*10);
a[7].wheel.spin(spinvalue);
a[7].wheel.gotoAndPlay(2);
e.target.removeEventListener(MouseEvent.CLICK,wheelspin);
a[7].addEventListener(MouseEvent.CLICK,wheelmove);
}
function wheelmove(e:MouseEvent)
{
a[7].x=1000;
e.target.addEventListener(MouseEvent.CLICK,wheelmove);
}
moveto();
}
public function moveto()
{
if(spinvalue==0||spinvalue==7||spinvalue==8||spinvalue==9)
{
if(nooflandsown==0)
{
/* the above one is working fine but,this error indicating below line*/
dialog2.x=200;
dialog2.dialogtext.text="you dont own any land";
dialog2.okbut.addEventListener(MouseEvent.CLICK,nothing2);
function nothing2(e:MouseEvent)
{
dialog2.x=1000;
e.target.removeEventListener(MouseEvent.CLICK,nothing2);
endturn();
}
}
else
{
dialog3.x=200;
dialog3.y=200;
dialog3.dialogtext.text="do you want to build";
dialog3.yesbut.addEventListener(MouseEvent.CLICK,wanttobuild);
dialog3.nobut.addEventListener(MouseEvent.CLICK,nothing3);
function wanttobuild(e:MouseEvent)
{
dialog3.x=1000;
e.target.removeEventListener(MouseEvent.CLICK,wanttobuild);
dialog3.nobut.removeEventListener(MouseEvent.CLICK,nothing3);
chooseland();
}
function nothing3(e:MouseEvent)
{
dialog3.x=1000;
dialog3.yesbut.removeEventListener(MouseEvent.CLICK,wanttobuild);
e.target.removeEventListener(MouseEvent.CLICK,nothing3);
endturn();
}
}
}
else
{
l=(currentposition+spinvalue)%18;
this.pos=l;
switch(currentposition)
{
case 1:
this.gotoAndPlay(15);
break;
case 2:
this.gotoAndPlay(25);
break;
case 3:
this.gotoAndPlay(35);
break;
case 4:
this.gotoAndPlay(55);
break;
case 5:
this.gotoAndPlay(65);
break;
case 6:
this.gotoAndPlay(75);
break;
case 7:
this.gotoAndPlay(85);
break;
case 8:
this.gotoAndPlay(105);
break;
case 9:
this.gotoAndPlay(115);
break;
case 10:
this.gotoAndPlay(125);
break;
case 11:
this.gotoAndPlay(135);
break;
case 12:
this.gotoAndPlay(145);
break;
case 13:
this.gotoAndPlay(165);
break;
case 14:
this.gotoAndPlay(175);
break;
case 15:
this.gotoAndPlay(195);
break;
case 16:
this.gotoAndPlay(205);
break;
case 17:
this.gotoAndPlay(215);
break;
default:
this.gotoAndPlay(1);
}
currentposition=l;
}
}
please help me out. i tried a lot by changing the entire code.but i cant figure that out
First, why adding event listener inside an event listener (function wheelmove)? And second, check if you actually exit moveto() function WITHOUT another call of salute(), if no, then you have to alter your code flow logic elsewhere. Also, in case of large code, you may use PasteBin service in the Internet to host the code.

Adobe AIR 3.2 Glitch

I just finished a successful build of my program last night. Then, I get up this morning, and after an update fro Adobe AIR 3.1 to AIR 3.2, I find THIS bug!
The same build under 3.1 works perfectly. However, as soon as 3.2 is installed, the following code after stopDrag fails silently. Mind you, it only fails in the packed and installed AIR application. It works perfectly when I test it inside of Adobe Flash Professional CS5.5
WHAT is going on? Here's the code I'm dealing with. Again, this works without error for Adobe AIR 3.1, but fails for 3.2. I cannot get to any other MouseEvent.MOUSE_UP events in my program at this point, due to my structure.
I omitted the irrelevant parts of the code. All the same, there is a lot, due to the fact that I don't know where the error occurs exactly. Instead of everything that is supposed to happen happening, stopDrag is the last line of code that fires in this block.
tile5.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler5);
function mouseUpHandler5(evt:MouseEvent):void
{
Mouse.cursor = "paw";
var obj = evt.target;
var target = obj.dropTarget;
obj.stopDrag();
if (target != null && target.parent == hsSlot1)
{
brdgcheck(5, 1);
}
}
function brdgcheck(tile:int, slot:int)
{
var ck_brdg_l:String = "osr.Langue.brdg_l" + String(slot);
var ck_brdg_t:String = "osr.Langue.brdg_t" + String(tile);
var ck_slotfilled:String = "Slot" + String(slot) + "Filled";
var ck_tile:String = "tile" + String(tile);
var ck_slot:String = "hsSlot" + String(slot);
var ck_txtTile:String;
switch(tile)
{
case 1:
ck_brdg_t = osr.Langue.brdg_t1;
ck_txtTile = tile1.txtTile1.text;
break;
case 2:
ck_brdg_t = osr.Langue.brdg_t2;
ck_txtTile = tile2.txtTile2.text;
break;
case 3:
ck_brdg_t = osr.Langue.brdg_t3;
ck_txtTile = tile3.txtTile3.text;
break;
case 4:
ck_brdg_t = osr.Langue.brdg_t4;
ck_txtTile = tile4.txtTile4.text;
break;
case 5:
ck_brdg_t = osr.Langue.brdg_t5;
ck_txtTile = tile5.txtTile5.text;
break;
}
switch(slot)
{
case 1:
ck_brdg_l = osr.Langue.brdg_l1;
break;
case 2:
ck_brdg_l = osr.Langue.brdg_l2;
break;
case 3:
ck_brdg_l = osr.Langue.brdg_l3;
break;
case 4:
ck_brdg_l = osr.Langue.brdg_l4;
break;
case 5:
ck_brdg_l = osr.Langue.brdg_l5;
break;
}
if (ck_brdg_l == ck_brdg_t)
{
osr.Sonus.PlaySound("concretehit");
this[ck_slotfilled].visible = true;
switch(slot)
{
case 1:
Slot1Filled.txtSlot1.text = ck_txtTile;
break;
case 2:
Slot2Filled.txtSlot2.text = ck_txtTile;
break;
case 3:
Slot3Filled.txtSlot3.text = ck_txtTile;
break;
case 4:
Slot4Filled.txtSlot4.text = ck_txtTile;
break;
case 5:
Slot5Filled.txtSlot5.text = ck_txtTile;
break;
}
this[ck_tile].visible = false;
this[ck_slot].visible = false;
if (hsSlot1.visible == false && hsSlot2.visible == false && hsSlot3.visible == false && hsSlot4.visible == false && hsSlot5.visible == false)
{
osr.Gradua.Score(true);
osr.Gradua.Evaluate("brdg");
btnReset.visible = false;
hsChar.visible = false;
if (osr.Gradua.Fetch("brdg", "arr_act_stcnt") < 4)
{
bga.gotoAndPlay("FINKEY");
win_key();
}
else
{
bga.gotoAndPlay("FINNON");
}
}
else
{
osr.Gradua.Score(true);
}
}
else
{
osr.Gradua.Score(false);
osr.Sonus.PlaySound("glassbreak");
switch(tile)
{
case 1:
tile1.x = 92.85;
tile1.y = 65.85;
break;
case 2:
tile2.x = 208.80;
tile2.y = 162.85;
break;
case 3:
tile3.x = 324.80;
tile3.y = 65.85;
break;
case 4:
tile4.x = 437.80;
tile4.y = 162.85;
break;
case 5:
tile5.x = 549.80;
tile5.y = 65.85;
break;
}
}
}
EDIT: I found a good workaround, to use "if (hsSlot1.hitTestPoint(mouseX,mouseY) && hsSlot1.visible == true)"
However, a solution to this problem would still be appreciated!