vendredi 1 juillet 2016

Tableau Filtering Error

I am attempting to use the JavaScript API to configure a default filter selection state. Here is the code I am using for this example:

$(function() {
  var placeholderDiv = document.getElementById("tableauViz");
  var url = "https://sometableausite/t/Tableau_Dev/views/MyPath/HomeDashboard?:embed=y&:showShareOptions=true&:display_count=no&:showVizHome=no";
  var options = {
     hideTabs: false,
     width: "100%",
     height: "1552px",
     onFirstInteractive: function() {
        var worksheet;


        var filtersVal='';
        var onSuccess = function (filters) {
            console.log("This worksheet has " + filters.length + " filter(s) associated with it.");
            $.each(filters, function (filter, i) {
                // use .value property of each DataValue object
                filtersVal += i.getFieldName() + ", ";
                console.log(filtersVal);
            });
        };

        var onError = function (err) {
            console.log(err);
        };

        viz.getWorkbook().activateSheetAsync("Performance").then(function(sheet) {
            worksheet = sheet;
            worksheet.getWorksheets()[0].getFiltersAsync().then(onSuccess, onError);
        });        
     }
  };

  var viz = new tableau.Viz(placeholderDiv, url, options);  
});

This is just trying to get the available filter options at this point but I am getting a 500 server error and getting kicked into the onError call when calling worksheet.getWorksheets()[0].getFiltersAsync().

Here is the error returned:

POST to https://sometableausite/vizql/t/Tableau_Dev/w/MyPath/v/HomeDashboard/sessions/E49DB48C495E4A858821B95F95AEFB20-0:2/commands/tabsrv/get-filter-info

gives a 500 server error.

TableauException: INTERNAL ERROR
2016-06-22 19:27:53.350 (V2rmuQrmAA0AAEGQy60AAALP,0,2)

What can I do to get the list of filters available?

PHP adding a 2 to a work week amount

I have a calendar that I am currently working on, everything is working great. Essentially when an event is added to the calendar it checks to see how many days the event is for. This works and it places it on the calendar, however, I don't want the events to span over the weekends and have found no way to do this in full calendar.js. So in my model on the backend I want to add 2 days to each event when requesting from the database for each increment of 5 days. Business hours are mon-fri. Sat-sun closed. So if event is 4 days no value added, however if is 6 days event would now be 8 and if 11 days it would now be 15 days etc. I have started to build a if elseif php statement to accommodate this, however is there a faster way in php to do the math of increments of 5.

$endDate = project['endDate']; //is my variable from database

So shared below is what I had been doing, but it is obviously a lot of coding there must be a better way

$endDate = 12 //number of days of tasks summed from the DB;

if ($endDate <= 5) {
      $endDate = $endDate 
} else if ($endDate > 5 && $endDate <= 10){ 
      $endDate = $endDate + 2;
} else if ($endDate > 10 && $endDate <= 15){
      $endDate = $endDate + 4; // would currently stop here
} else if ($endDate > 15 && $endDate <= 20){
      $endDate = $endDate + 6;
} else if ($endDate > 20 && $endDate <= 25){
      $endDate = $endDate + 8;
} else if {.........// continue this, must be a better way as I have to goto 100000....

php regex replace local relative pathways

I have multiple relative links that are included in a string. However I want too have all the links replace with a simple javascript:alert("Sorry You Cannot Do That.") and I do not want any absolute pathways such as http://google.com to change only the relative pathways such as /conf/bin.html.

Here is an example code snippet:

$pattern = "/<a(.*) href='/(.*)'(.*)>reply</a>/";
$string = "<a target='_blank' href='/conf/bin?post=5760627b29ba0' name='bin' id='bin' class='bin' title='Hide From Feed'></a>
wow
<a target='_blank' href='/conf/bin?post=5760627b29ba0' name='bin' id='bin' class='bin' title='Hide From Feed'></a> wow";
while (preg_match($pattern, $string)){

$string = preg_replace($pattern, "<tr><td align='right'><a href='javascript:alert(" . chr(34) . "Sorry You Cannot Do That" . chr(34) . ")' style='text-decoration:none;'>reply</a>", $string);
}

And I want the string to end up as:

$string = "<a target='_blank' href='javascript:alert(" . chr(34) . "Sorry You Cannot Do That" . chr(34) . ")' name='bin' id='bin' class='bin' title='Hide From Feed'></a>
wow
<a target='_blank' href='javascript:alert(" . chr(34) . "Sorry You Cannot Do That" . chr(34) . ")' name='bin' id='bin' class='bin' title='Hide From Feed'></a> wow";

Can anyone help. Thanks

ajax form submit without refresh error

I have a form in AJAX working, but when i have more than one form on the same page appears an error.

    <script>
  var fmx = jQuery.noConflict();
    fmx(document).ready(function(){
    fmx('form').on('submit', function (e) {
      e.preventDefault();
      fmx.ajax({
        type: 'post',
        url: 'https://www.webshop.com/post.php',
        data: fmx('form').serialize(),
        success: function () {
           document.getElementById('#form_post').style.display = 'none';
           document.getElementById('#form_result').style.display = '';
        }
      });
    });
  });
</script>
<div id="#form_post" style="display:inherit">
<form class="form_post">
    <label for="post_email">FORM</label>
    <input id="post_email" class="post_email" type="email" name="post_email" placeholder="your@email.com" required>
    <input id="post_data" class="post_data" type="text" name="post_data" placeholder="MSG" required>
    <input name="submit" type="submit" value="POST" >
</form>
</div>
<div id="#form_result" style="display:none"><br>Success.</div>

I tried to switch to a #id but it stopped working.

    <script>
  var fmx = jQuery.noConflict();
    fmx(document).ready(function(){
    fmx('#form').on('submit', function (e) {
      e.preventDefault();
      fmx.ajax({
        type: 'post',
        url: 'https://www.webshop.com/post.php',
        data: fmx('#form').serialize(),
        success: function () {
           document.getElementById('#form_post').style.display = 'none';
           document.getElementById('#form_result').style.display = '';
        }
      });
    });
  });
</script>
<form class="form_post" id="form">

How do put an ID on this form?

How to insert author meta inside google adsense javascript in wordpress functions.php

I am trying to insert Author meta i.e Google adsense Publisher ID and Adunit slot number in functions.php for wordpress. The code am using displays this metas as text e.g xxxxxxxxxxxxxxxxxxx i.e both the ID and slot number in same line on the web page and does not show the google adsense script/ad unit.

CODE

    //RECTANGLE Adsense UNit
function get_rectangle() {
    global $post; $author_id=$post->post_author;

            if(is_single()) { 

$rec_Ad.= '<div>';
            $rec_Ad.= '<script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
            <!-- 300x250 -->
            <ins class="adsbygoogle"
                 style="display:inline-block;width:300px;height:250px"';

    if (get_the_author_meta('rectangle', $author_id)) { 

                 $rec_Ad.= 'data-ad-client="ca-pub-'.the_author_meta('pub-id', $author_id).'"';
                 $rec_Ad.= 'data-ad-slot="'.the_author_meta('rectangle', $author_id).'"></ins>';

                 } else {

                 $rec_Ad.= 'data-ad-client="ca-pub-xxxxxxxxxxxxxxx"';
                 $rec_Ad.= 'data-ad-slot="xxxxxxxxxxxxxxxxxx"></ins>';
            }

            $rec_Ad.= '<script>
            (adsbygoogle = window.adsbygoogle || []).push({});
            </script></div>';
   } 

    return $rec_Ad;
}

MAIN FOCUS

$rec_Ad.= 'data-ad-client="ca-pub-'.the_author_meta('pub-id', $author_id).'"';
$rec_Ad.= 'data-ad-slot="'.the_author_meta('rectangle', $author_id).'"></ins>';

The code is supposed to display in single.php page, the ad unit of author if it exists else show the default ad unit.

How to change the trackID of the Soundcloud API?

I have a site that will make use of the Soundcloud API, to play different tracks.

Perhaps I have some issues with switching between tracks and play/pause the active track. I think this has to do with the trackID and the first if statement of SCPlayer, because it will be true after you clicked the first track and it will be forever be true (only if you refresh it will be reset naturally).

My code looks like this:

var SCPlayer;
            var isPlaying = false;

            function player(trackID) {
                console.log(trackID);

                if (SCPlayer) {

                    if (isPlaying) {
                        SCPlayer.pause();
                        isPlaying = false;
                    } else {
                        SCPlayer.play();
                        isPlaying = true;
                    }

                } else {
                    // SC.stream('/tracks/' + trackID, function(sound) { 
                    SC.stream('/tracks/' + trackID).then(function(player) { 
                        SCPlayer = player;
                        SCPlayer.play();
                        isPlaying = true; 

                        SCPlayer = false;
                    });
                }

            }

            $('.control').click(function(event) {
                event.preventDefault();
                var trackID = $(this).closest('li').attr('data-id');
                // console.log(trackID);

                if ( $(this).hasClass('play') ) {
                    $('#playlist li a').removeClass('pause');
                    $(this).removeClass('play').addClass('pause');
                } else {
                    $('#playlist li a').removeClass('pause');
                    $(this).addClass('play');
                }

                player(trackID);
            });

The above code will play the selected track. When you select another track it will play the another song. But I can't pause / play the selected track. When I remove SCPlayer = false; the play/pause functionality will work and switching between tracks not, because what I mentioned before, it will hold the latest trackID.

Does anyone know a working solution for this? So that you can play/ pause the track and switch between tracks.

Thanks in advance.

How to make a dynamic input tree in java script

Im trying to make somthing like this for a website

[category name (textbox)]
[add sub category (button to js function which creates sub category)]
[sub category field (textbox)]
[add sub category (button to js function which creates sub sub category)]
[sub-sub category field (textbox)]
[add sub category (button to js function which creates sub sub sub category)]

and so on...

so basically a large 'unlimited tree' where you can add as many categories, sub categories and sub, sub, sub, sub... categories as you want.

Here's what I have so far...

<body>
<script>
    var category = Array();
    var iter = 0;

    function addCategory(div){
        category[iter] = ["", 0];
        newElement = document.createElement('div');
        var content = '<input type="text" onchange="category[' + iter + '][0] = this.value">
                       <div id="new-sub" style="padding-left: 20px">
                          <button onclick="addSub('new-sub', ' + category[iter][1] + ', ' + iter + ')">Add Sub-category</button>
                       </div>';
        newElement.innerHTML = content;
        document.getElementById(div).appendChild(newElement);
        iter++;
    }

    function addSub(div, ID, iter){
        //here lies my confusion
    }

</script>
<div id="new-elements">
</div>
<button onclick="addCategory('new-elements')" >Add Element</button>
</body>

I the idea is to store the textbox values in an array as the user changes them. Only issue is I cant seem the get the multi-dimension array part right...

I'm an extreme beginner to JS, can anyone help me find a solution?