人人商城

form.html 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <div class="panel panel-default">
  2. <div class="panel-heading">
  3. 回复内容
  4. </div>
  5. <ul class="list-group">
  6. <li class="list-group-item" ng-repeat="item in context.items" id="append-list">
  7. <div class="form-group">
  8. <label class="col-xs-12 col-sm-3 col-md-2 control-label">音频标题</label>
  9. <div class="col-sm-9 col-xs-12">
  10. <input type="text" class="form-control" placeholder="添加音乐消息的标题" name="title[]" ng-model="item.title">
  11. </div>
  12. </div>
  13. <div class="form-group">
  14. <label class="col-xs-12 col-sm-3 col-md-2 control-label">音频链接</label>
  15. <div class="col-sm-9 col-xs-12" ng-invoker="context.bind($index, item);">
  16. {php echo tpl_form_field_audio('url[]', '', array('extras' => array('text' => 'ng-model="item.url"')));}
  17. <span class="help-block">选择上传的音频文件或直接输入URL地址,常用格式:mp3</span>
  18. </div>
  19. </div>
  20. <div class="form-group">
  21. <label class="col-xs-12 col-sm-3 col-md-2 control-label">高品质链接</label>
  22. <div class="col-sm-9 col-xs-12">
  23. <input type="text" class="form-control" placeholder="" name="hqurl[]" ng-model="item.hqurl">
  24. <span class="help-block">没有高品质音乐链接,请留空。高质量音乐链接,WIFI环境优先使用该链接播放音乐</span>
  25. </div>
  26. </div>
  27. <div class="form-group">
  28. <label class="col-xs-12 col-sm-3 col-md-2 control-label">描述</label>
  29. <div class="col-sm-9 col-xs-12">
  30. <textarea style="height:80px;" class="form-control" cols="70" name="description[]" ng-model="item.description" placeholder="添加音乐消息的简短描述" ></textarea>
  31. <span class="help-block">描述内容将出现在音乐名称下方,建议控制在20个汉字以内最佳</span>
  32. </div>
  33. </div>
  34. <div class="form-group">
  35. <div class="col-sm-offset-2 col-md-offset-2 col-lg-offset-1 col-xs-12 col-sm-10 col-md-10 col-lg-11">
  36. <a href="javascript:;" class="btn btn-default hidden" ng-click="context.saveItem(item);">{{item.saved ? '编辑' : '保存'}}</a>
  37. <a href="javascript:;" class="btn btn-default" ng-click="context.removeItem(item);">删除</a>
  38. </div>
  39. </div>
  40. </li>
  41. </ul>
  42. <div class="panel-footer">
  43. <a href="javascript:;" class="btn btn-default" ng-click="context.addItem();">添加语音回复</a>
  44. <span class="help-block">添加多条回复内容时, 随机回复其中一条</span>
  45. </div>
  46. </div>
  47. <script>
  48. window.initReplyController = function($scope) {
  49. $scope.context = {};
  50. $scope.context.items = {php echo json_encode($replies)};
  51. if(!$.isArray($scope.context.items)) {
  52. $scope.context.items = [];
  53. }
  54. if($scope.context.items.length == 0) {
  55. $scope.context.items.push({});
  56. }
  57. $scope.context.bind = function(i, v) {
  58. $('input[name="url[]"]').eq(i).val(v.url);
  59. };
  60. $scope.context.addItem = function(){
  61. $scope.context.items.push({});
  62. };
  63. $scope.context.saveItem = function(item){
  64. item.saved = !item.saved;
  65. };
  66. $scope.context.removeItem = function(item) {
  67. require(['underscore'], function(_){
  68. $scope.context.items = _.without($scope.context.items, item);
  69. $scope.$digest();
  70. });
  71. }
  72. };
  73. window.validateReplyForm = function(form, $, _, util, $scope) {
  74. $scope.$digest();
  75. var error = false;
  76. angular.forEach($scope.context.items, function(v, k){
  77. v.url = $('input[name="url[]"]').eq(k).val();
  78. //音频标题和链接不能为空(两种链接至少有一种)
  79. if(!$.trim(v.title) || (!$.trim(v.url) && !$.trim(v.hqurl))) {
  80. error = true;
  81. }
  82. });
  83. if(error) {
  84. util.message('必须输入音频标题和音频链接.');
  85. return false;
  86. }
  87. return true;
  88. };
  89. </script>