13 Replies - 821 Views - Last Post: 08 September 2015 - 03:40 PM

#1 JianuM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-September 15

I am trying to get query and edit it from Admin Panel

Posted 05 September 2015 - 08:14 AM

Hello guys,

I am trying for a week to implement this Admin Pannel : http://tinypic.com/v...pic=2hoz0ad&s=8

I succeeded to display the queries from parse.com but I can't figure out how to edit them from admin panel. I read the parse.com documentation and I have an idea how should it work but I can write the code for that, I tried to make the editUser function but I don't know what is missing from my code. Can somebody help me with a method?

<!DOCTYPE html>
<html>
<head>
    <script type="text/javascript" src="js/parse-1.5.0.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
</head>
<body ng-app="demo">
    <div class="container" ng-controller="adminPannel">
        <table class="table table-striped">
            <thead>
                <tr>
                    <th>Username</th>
                    <th>First Name</th>
                    <th>Last Name</th>
                </tr>
            </thead>
            <tbody><tr ng-repeat="user in users">
                    <td><button class="btn" ng-click="editUser()"><input type="text" id="newUserName" ng-model="firstNameCh"/></button></td>
                    <td>{{ user.firstname }}</td>
                    <td>{{ user.lastname }}</td>
                </tr>
            </tbody>
        </table>
    </div>
</body>
</html>


And here is my main.js
var app=angular.module('demo',[]);
app.controller('adminPannel',['$scope',function($scope) {
$scope.users=[];

Parse.initialize("WnaPPAytzCE8AR7NNGENpVGMGQ6pQ9wH2LKRQ6wE", "2qfXZunNrQPnCgNuusPpbGCDmbRBzo7CG4X0edDF");
$scope.use=Parse.User.current();
var noname2=Parse.Object.extend("noname2");
var query=new Parse.Query(noname2);
//query.equalTo("uname",$scope.use.get('username'));
query.find({
  success:function(results) {
  alert("success");
  alert(results.length);
  for(var i=0;i<results.length;i++)
   {
     var object= results[i];

     $scope.users.push({'firstname':object.get('firstname') , 'lastname':object.get('lastname') ,'age':object.get('age')});

   }
    $scope.$apply();
 },
 error:function(error) {
  alert("error:"+ error.code +" "+error.message);
   }
});
$scope.editUser = function(){
  noname2SubClass.save(null,{
    success:function(noname2SubClass){
      noname2SubClass.set('firstname', $scope.firstNameCh);
      noname2SubClass.save();
    }
  });
}
}]);


Is This A Good Question/Topic? 0
  • +

Replies To: I am trying to get query and edit it from Admin Panel

#2 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2039
  • View blog
  • Posts: 6,247
  • Joined: 15-January 14

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 10:14 AM

Are you getting error messages in your browser? It sounds like noname2SubClass would be undefined.
Was This Post Helpful? 1
  • +
  • -

#3 JianuM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-September 15

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 11:02 AM

I changed a little that function and now I can change these strings but I don't know why it behave wierd. I mean when you add firstname and lastname and then click on the save button, all rows are changing.

Look here: http://plnkr.co/edit...IDqcX?p=preview
Refresh the page to see the changes you made, after you click on the button.

It should change only the current user where you add the new first and lastname.
Was This Post Helpful? 0
  • +
  • -

#4 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2039
  • View blog
  • Posts: 6,247
  • Joined: 15-January 14

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 11:17 AM

I don't know what I'm supposed to be looking at on that site. If you can host a demo yourself that might be better than trying to put it into one of the online editing sites.
Was This Post Helpful? 0
  • +
  • -

#5 JianuM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-September 15

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 11:19 AM

It is hosted: http://codetheweb.net/backup/parse/

But there you could see the code too. That's why I putted that link.
Was This Post Helpful? 0
  • +
  • -

#6 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2039
  • View blog
  • Posts: 6,247
  • Joined: 15-January 14

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 11:29 AM

I see 8 text fields and 4 buttons that are about 2 pixels tall, and not much else happens. I don't know what is supposed to happen.
Was This Post Helpful? 0
  • +
  • -

#7 JianuM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-September 15

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 11:35 AM

Text from the right Firstname and lastname, that text is fetched from parse.com, something is wrong in my code because when you add text in those inputs all text from the right change.
It should work like that: when you add text in first row (those 2 inputs) and then click on the button, only the first row should be updated, not all.

Add what text you want on those inputs > click on button and then refresh the page
Was This Post Helpful? 0
  • +
  • -

#8 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2039
  • View blog
  • Posts: 6,247
  • Joined: 15-January 14

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 11:52 AM

All 4 buttons also only pull information from the first 2 fields, not the fields next to the button. The reason for that is because you gave all of the input fields the same ID, so when you try to get a field with that ID it gets the first one on the page.

In your editUser function you call query.find, and that returns a list of all 4 users. You loop through those users and set the firstname and lastname of each one to the same values (the values of the first set of fields, since all of them have the same ID), and save each user.
Was This Post Helpful? 0
  • +
  • -

#9 JianuM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-September 15

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 11:55 AM

yes, I know but what I don't know is how to edit the function to work properly.
Was This Post Helpful? 0
  • +
  • -

#10 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2039
  • View blog
  • Posts: 6,247
  • Joined: 15-January 14

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 12:04 PM

If you want to keep doing what you're doing, and save every user when any button is pressed, then you need to use the user IDs in your field IDs. Get the list of users, loop over them, and use their user ID to look up only their firstname and lastname. That means you need to use their user ID in the field ID.
Was This Post Helpful? 1
  • +
  • -

#11 JianuM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-September 15

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 12:15 PM

I am not sure I understand what actually I need to do. I am begginer with parse and angular, should I edit all editUser function? Because I am sure if I will accomplish what I need with query.find().
Was This Post Helpful? 0
  • +
  • -

#12 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2039
  • View blog
  • Posts: 6,247
  • Joined: 15-January 14

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 12:29 PM

You'll need to change the field IDs to add the user ID to each field ID, and you'll need to change the function to look up the fields with the user ID as part of the field ID.
Was This Post Helpful? 0
  • +
  • -

#13 JianuM   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 9
  • Joined: 05-September 15

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 12:35 PM

So, instead of noname2 var, I should use the equalTo(key, value) ? I mean that is the right way to make that, if I use qurey.first() it will work good but only for first row, I mena only first will be change.

$scope.editUser = function(){
  var noname2=Parse.Object.extend("noname2");
  query.find({
    success:function(results){
      for ( var i=0; i<results.length; i++){
        var obj = results[i];
        obj.set('firstname', $('#frstName').val());
        obj.set('lastname', $('#lstName').val());
        obj.save();
      }
    },
    error:function(error){
      alert('error' + error.code + ' ' + error.message);
    }
  });
}

Was This Post Helpful? 0
  • +
  • -

#14 ArtificialSoldier   User is offline

  • D.I.C Lover
  • member icon

Reputation: 2039
  • View blog
  • Posts: 6,247
  • Joined: 15-January 14

Re: I am trying to get query and edit it from Admin Panel

Posted 08 September 2015 - 03:40 PM

I'm not familiar with the parse API, I'm not sure what you have available. I suggested a way to just change the field IDs so that your current code will work. You could also remove the various edit buttons and just have a single edit button since it will save everyone. If you want to save only 1 record at a time then I would imagine that you will still use the unique user ID to tell it which user to save.

Either way, the major point of this is that you need to have a unique ID for every field on your page. Right now you have 4 fields with the ID "frstName", and 4 fields with the ID "lstName", and that is what is causing the problems. IDs need to be unique on a page.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1