The forum of the forums
Would you like to react to this message? Create an account in a few clicks or log in to continue.

LocalStorage Coding help

3 posters

Go down

Solved LocalStorage Coding help

Post by Astariel March 4th 2019, 4:02 am

So, I was having trouble with a status update widget the other day. I did manage to get it fixed thanks to Twisted. However, I am having a small problem editing the LocalStorage script to work with the widget. The widget isn't showing the current status, which leads me to believe that it's due to not setting up the LocalStorage script correctly due to my lack of knowledge in Java. Below are the current codes I have for the widget and widget's Java page.

Any assistance in setting up the LocalStorage script would be amazing. I'm so lost with Java x.x

Widget Code
Code:
 <div align="center">
             <span id="tm_currstat">Current Status:</span><br /><br />         
   <div class="form-group row p-2">
                        <label for="input-text-help" id="tmst_stnotice" class="control-label"></label>                 
      <div class="input-group">
                                              
         <div class="input-group-prepend">
                                    <span class="input-group-text"><em class="fa fa-paypal"></em></span>                             
         </div>
                               <input maxlength="150" type="text" class="form-control" id="tstatus" value="" />                           
      </div>
                                                           
   </div>
                    
   <div class="form-group row p-2">
                                       
      <button class="btn btn-light px-5" type="button" onclick="updstatus()">
                               <em class="fa fa-floppy-o mr-1" id="tmst_stnotice"> </em> Save Status                       
      </button>
                                                     
   </div>
</div>


Widget Java Code
Code:
 jQuery(function()
{
var id = 'field_id1';
 
  dataStore.set('Stat', '', 60*1000);
  if(dataStore.get('Stat').value =="")
  {
      jQuery.get('/u'+_userdata.user_id, function (data)
      {
        var cstat= jQuery('#'+id+' .field_uneditable', data).eq(0).text();
        jQuery('#tm_currstat').text('Current Status: '+cstat);
        jQuery('#tstatus').val(cstat);
        dataStore.set('Stat', cstat, 60*1000);
      })
  }else{
      jQuery('#tstatus').val(cstat);
      jQuery('#tm_currstat').text('Current Status: '+dataStore.get('Stat').value);
  }
});
 
function updstatus()
{
  var id = 'field_id1';
  var name = 'profile_field_13_8';
 
  jQuery.getScript('https://illiweb.com/rs3/86/frm/jquery/json/jquery.json-1.3.min.js', function()
  {
      jQuery('#tmst_stnotice').text('Updating.');
      var content = new Array();
      var newstat = jQuery('#tstatus').val();
      content.push(new Array(name, newstat));
      jQuery.post('/ajax_profile.forum?jsoncallback=?', {
            id: id.substring(8, id.length),
            user: _userdata.user_id,
            active: '1',
            content: jQuery.toJSON(content),
            tid: document.getElementById('logout').href.replace(/.*tid=(.*?)&.*/,'$1')
        },function(data)
        {
           
            jQuery.get('/u'+_userdata.user_id, function (data)
            {
              var cstat= jQuery('dl:contains(Status) .field_uneditable', data).eq(0).text();
              if (jQuery('#tstatus').val()==cstat)
              {
                  jQuery('#tm_currstat').text('Current Status: '+cstat); 
                  dataStore.set('Stat', cstat, 60*1000);
                  jQuery('#tmst_stnotice').text('Done...');
              }else{
                  jQuery('#tmst_stnotice').text('Error Try Again.');
              }
            })
        }, 'json');
  });
};


Last edited by Astariel on March 6th 2019, 12:01 am; edited 2 times in total
Astariel
Astariel
New Member

Female Posts : 16
Reputation : 3
Language : English
Location : USA

Http://Astariel.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by _Twisted_Mods_ March 4th 2019, 12:10 pm

the local storage code from that page you just copy the first code box and create a new javascript and run it on the pages you need it on no changes are needed
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2083
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by Astariel March 5th 2019, 12:37 am

@_Twisted_Mods_

I don't need to set up any of the set or get functions? If not, does the status widget just not keep track of the current status like the widget shows?
Astariel
Astariel
New Member

Female Posts : 16
Reputation : 3
Language : English
Location : USA

Http://Astariel.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by _Twisted_Mods_ March 5th 2019, 1:36 am

the get and set functions are already setup in the code for the status widget .. all it does is prevent the widget from making the request to get the status every time the page loads. it saves it for a hour then it will make the request again when the page is loaded. this will prevent a large load on your website if you had a lot of users opening pages with the widget on it
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2083
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by Astariel March 5th 2019, 2:57 am

@_Twisted_Mods_

So, the widget itself should only show the status when they update it? And it'll only stay on the until they reload the page?
Astariel
Astariel
New Member

Female Posts : 16
Reputation : 3
Language : English
Location : USA

Http://Astariel.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by _Twisted_Mods_ March 5th 2019, 11:21 pm

the status will load each time the page is loaded but it does not grab the status each time it only grabs it once every hour no matter how many times its loaded unless the user changes the status then it will grab the new status
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2083
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by Astariel March 5th 2019, 11:25 pm

@_Twisted_Mods_

Oh, well that's my problem with it then. It's not grabbing the status. Like, once you add your status, it shows until you leave the page. Then it just says 'Current Status: '. It never grabs the current status. That's why I thought I set the LocalStorage up wrong x.x
Astariel
Astariel
New Member

Female Posts : 16
Reputation : 3
Language : English
Location : USA

Http://Astariel.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by _Twisted_Mods_ March 5th 2019, 11:28 pm

you might have because that's where it saves the status and keeps it from updating every time the page loads. pm me a test account and ill check it out
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2083
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by Astariel March 5th 2019, 11:44 pm

@_Twisted_Mods_

Admin test account? C:
Astariel
Astariel
New Member

Female Posts : 16
Reputation : 3
Language : English
Location : USA

Http://Astariel.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by _Twisted_Mods_ March 5th 2019, 11:49 pm

it would make it easier
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2083
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by Astariel March 5th 2019, 11:52 pm

@_Twisted_Mods_

Okay. Just wanted to make sure C: Pm'd you the account info.
Astariel
Astariel
New Member

Female Posts : 16
Reputation : 3
Language : English
Location : USA

Http://Astariel.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by _Twisted_Mods_ March 5th 2019, 11:58 pm

i missed a part of the code when i was changing stuff

in the first script
Code:

var cstat= jQuery('#'+id+' .field_uneditable', data).eq(0).text();

had to be changed to

Code:

 var cstat= jQuery('dl:contains(Status) .field_uneditable', data).eq(0).text();


can you confirm its working now?
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2083
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by Astariel March 6th 2019, 12:01 am

@_Twisted_Mods_

You are literally a coding genius, Twisted. It's grabbing the current status perfectly now! Thank you so much! <3
Astariel
Astariel
New Member

Female Posts : 16
Reputation : 3
Language : English
Location : USA

Http://Astariel.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by _Twisted_Mods_ March 6th 2019, 12:02 am

Awesome glad i could help
_Twisted_Mods_
_Twisted_Mods_
Helper
Helper

Male Posts : 2083
Reputation : 336
Language : English
Location : Ms

http://liquidcode.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by Astariel March 6th 2019, 12:05 am

@_Twisted_Mods_

You have many times in the past and especially now!


Marked as solved.
Astariel
Astariel
New Member

Female Posts : 16
Reputation : 3
Language : English
Location : USA

Http://Astariel.forumotion.com

Back to top Go down

Solved Re: LocalStorage Coding help

Post by Ape March 6th 2019, 12:10 am

Thank you so much for your help @_Twisted_Mods_
Problem solved & topic archived.
Please read our forum rules: ESF General Rules


LocalStorage Coding help Left1212LocalStorage Coding help Center11LocalStorage Coding help Right112
LocalStorage Coding help Ape_b110
LocalStorage Coding help Ape1010
Ape
Ape
Administrator
Administrator

Male Posts : 19369
Reputation : 2006
Language : fluent in dork / mumbojumbo & English haha

http://chatworld.forumotion.co.uk/

Back to top Go down

Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum